Add a string as a mail attachment text file.

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.
 
P

Pete Wright

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.


_____________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top