Hi,
I want to attach a Mailmessage as an attachment to a Mailmessage. How can I achieve this the best way?
Thanks in advance.
Attach MailMessage as Attachment to a Mailmessage
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 17, 2010, 4:54 AM EDT
Here is the code to attach the file with your mail message:
string file = "data.xls"; // Create a message and set up the recipients. MailMessage message = new MailMessage( "[email protected]", "[email protected]", "Quarterly data report.", "See the attached spreadsheet."); // Create the file attachment for this e-mail message. Attachment data = new Attachment(file, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(file); disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); disposition.ReadDate = System.IO.File.GetLastAccessTime(file); // Add the file attachment to this e-mail message. message.Attachments.Add(data);Hope it helps you.
Please mark as answer if it helps.
Andre11 reputationPosted Mar 17, 2010, 5:05 AM EDT