+1 vote

Hi,

Sometimes, the function GetMessageByUID does not always find the attachments.
Here is my code:

var eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder().CreateFromEml(eml);
MimeData attachment = null;
foreach (MimeData attachmentTemp in email.Attachments)
{
      if (attachmentTemp is IMailContainer)
      {
          attachment = attachmentTemp;
          break;
      }
}

Sometimes, "email.attachments" return an object of type "MimeRfc822" and other times, it return an object "MimeRfc822Headers"

If we try to get the attachment back from the object "MimeRfc822Headers", we only get an empty mail.

So here my question, why does sometimes GetMessageByUID return the attachments and the other time it does not.

Sorry for bad english.

by

1 Answer

0 votes
  1. Imap.GetMessageByUID always returns entire email message as it is stored on the IMAP server. What you see are simply different email message kinds. message/rfc822 MIME entity (MimeRfc822) is used to store entire emails, message/rfc822-headers (MimeRfc822Headers) to store only email headers.

  2. Use IMail.ExtractAttachmentsFromInnerMessages() if you want to process attachments that are parts of attached emails:

    ReadOnlyCollection<MimeData> attachments = 
        mail.ExtractAttachmentsFromInnerMessages();
    
    foreach (MimeData att attachments )
    {
        string fileName = att.SafeFileName;
        byte[] data = att.Data;
    
        att.Save("c:\\"+att.SafeFileName);
    }
    
  3. MimeRfc822Headers instance, as the name implies, contains only message headers - you'll not find any attachment data there.

by (297k points)
...