How can I delete attachments from a mail?

0 votes
asked Apr 12, 2013 by Rebex KB (8,210 points)
edited Dec 23, 2013

Hi,

can you send me an example of how to delete an attachment from a MailMessage with Rebex?

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Apr 12, 2013 by Tomas Knopp (58,580 points)
edited Apr 12, 2013
 
Best answer

Hello,

you can delete all attachments matching the "filename" like this:

                MailMessage mail = new MailMessage();
                mail.Load(@"C:\temp\mail.eml");

                for (int i = 0; i < mail.Attachments.Count; i++)
                {
                       Attachment item = mail.Attachments[i];

                       if (item.FileName == "filename")
                       {
                              mail.Attachments.RemoveAt(i);
                              i--;
                       }
                }
...