If you already have an IMail
instance there are 2 ways of filtering attachments by its content:
Use MimeBase.ContentType
:
if (attachment.ContentType == ContentType.ApplicationPdf)
{
// process attachment as pdf
}
Please note that a sender may use more generic 'application/octet-stream' content type, instead of the more precise one: 'application/pdf'.
Use MimeData.SafeFile
and look at the file's extension:
if (Path.GetExtension(attachment.SafeFileName) == ".pdf")
{
// process attachment as pdf
}
You can use Linq to simplify it:
IMail email = ...;
var pdfs = email.Attachments
.Where(x => x.ContentType == ContentType.ApplicationPdf);