Add a string as a mail attachment text file.

  • Thread starter Thread starter Larry Viezel
  • Start date Start date
L

Larry Viezel

I have a string:

sring Result = "This is the string I want sent as a text file"

I have MailMessage:

MailMessage TestMail = new MailMessage();
TestMail.From = "(e-mail address removed)";
TestMail.To = "(e-mail address removed)";
TestMail.BodyFormat = MailFormat.Text;
TestMail.Subject = "Test email";
TestMail.Body = "This would be the body of the email"


I want to add Result as a textfile attachement to the email. How can I
go about doing this? I would prefer if I didn't have to actually save
to the disk.

TestMail.Attachments.Add(Result); //obviously this would be too
easy.
SmtpMail.Send(TestMail);

Any thoughts? Can I somehow cast this string into a MailAttachment as
if by magic?

Larry.
 
I think you are going to have to do the thing you don't want to do, which is
persist the string to a file, and then attach the file. On the upside, once
the mail is sent, there is nothing stopping your app from deleting the file.


--
Peter Wright
Author of ADO.NET Novice To Pro, from Apress Inc.


_____________________________
 
Back
Top