Remove attachements and save as .eml

Aug 12, 2012 at 2:54 PM

Hi,

Is there a way to remove attachments from mail and save the mail without attachments to disk as .eml

Thanks,

Ofir

Coordinator
Aug 16, 2012 at 5:47 AM

Hi.
Here is a sample code to do it.

----------------------------------------------------------------------------------------------------------
private void CreateEmlFile(MailMessage message)
{
    MailMessage mg = message;
    SmtpMessage smg = new SmtpMessage();
    foreach (var field in mg.Header)
    {
        smg[field.Key] = field.Value;
    }
    smg.BodyText = mg.BodyText;
    String text = smg.GetDataText();
    File.WriteAllText("C:\\mymail.eml", text);
}
----------------------------------------------------------------------------------------------------------



May 1, 2014 at 10:52 AM
Edited May 1, 2014 at 10:52 AM
I want to save Attachment as well in the eml file... so how can i do that ?
Coordinator
May 7, 2014 at 9:57 AM
You can save attachment as file as
private void CreateEmlFile(MailMessage message)
{
     MailMessage mg = message;
     SmtpMessage smg = new SmtpMessage();
     foreach (var field in mg.Header)
     {
         smg[field.Key] = field.Value;
     }
     smg.BodyText = mg.BodyText;
     String text = smg.GetDataText();
     File.WriteAllText("C:\\mymail.eml", text);

     var content = mg.Contents[0];
     content.SaveTo("C:\\yourFile.png");
}
May 9, 2014 at 4:13 PM
Hey Higty first of all thanks for your reply... But You didn't understand what my requirement is ?

Actually I don't want to download the attachment but my requirement is I want to embedded the attachment in my eml or msg file. Can I do that ?