Check opened file is an email before processing

Hi


Sometimes attachments to emails have no file extension, if I treat them as emails ehe Aspose library will open a file even if it’s not an email when I use:

Aspose.Email.Mail.MailMessage mailMsg = Aspose.Email.Mail.MailMessage.Load(filePath)

However some subsequent processing can fail/hang when I then try to process the attachment, is there a way I can validate if the mailMsg is actually an email, I looked at all the parameters but can’t seem to find one that works.

Thanks

Simon

Hi Simon,

Thank you for contacting Aspose Support team.

In such case, where the attachment extension is not available and you want to determine if the attachment is an email message, please use the following code sample that determines if the content type of the attachment is that of an email message. Please try it at your end and let us know your feedback.

Sample Code:

MailMessage myMsg = MailMessage.Load(“CompoundMessage.msg”);
int i = 0;

foreach (Attachment a in myMsg.Attachments)
{
if (a.ContentType.MediaType.Equals(“message/rfc822”))
{

}
}

That works great, thanks.

Hi Simon,

Thank you for sharing your feedback and please feel free to write to us in case you have any other query.