+2 votes

In my reading emails from mail server, some email contains .eml file that I need to read as IMail message, can you pls help me how I can identify those .eml attachment and process them - like get attachment from it.

by
edited by

1 Answer

0 votes

The easiest way is using IMail.ExtractAttachmentsFromInnerMessages method.

It extracts all attachments from the email and from all attached messages. It returns easy to use collection of MimeData objects, that represent each attachment.

IMail mail = new MailBuilder().CreateFromEml(
    imap.GetMessageByUID(uid));

ReadOnlyCollection<MimeData> attachments = 
    mail.ExtractAttachmentsFromInnerMessages();

foreach (MimeData mime in attachments)
{
    byte[] bytes = mime.Data;
    string fileName = mime.SafeFileName;
}

If you want to implement more complex processing take a look at Process emails embedded as attachments article. It describes how to traverse entire MIME tree.

by (297k points)
...