0 votes
by (8.4k points)
edited

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
by (58.9k points)
edited
 
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--;
                       }
                }
...