0

I'm using openpop to retrieve and process emails, In processing the mails, I'm checking for attachments and saving them to a specific folder. This works fine for csv files but for some reason for pdfs "att.Name" is returning null and won't save.

AttachmentCollection attachments = mailItem.Attachments;
foreach (Attachment att in attachments)
{
    using (var fileStream = new FileStream(conf.AttachmentSaveTo + att.Name,   FileMode.Create, FileAccess.Write))
    {
        att.ContentStream.CopyTo(fileStream);
    }
}

Any help, much appreciated.

user1801525
  • 125
  • 2
  • 5
  • 16

1 Answers1

0

Without having access to the raw message, it's possible that the MIME headers for your pdf attachments do not specify a file name.

If you look at the raw message source, check to see if your pdf attachments have a Content-Disposition header and make sure that they have a filename parameter.

If not, does the Content-Type header have a name parameter?

If at least 1 of those 2 parameters is present, perhaps you have discovered a bug in OpenPOP. If that's the case, I would suggest using my MailKit library instead.

jstedfast
  • 35,744
  • 5
  • 97
  • 110