by Dave
25. November 2011 06:21
Every few months, I get a question from a developer about aspNetMime not properly finding all the attachments in an email.
Almost all of the time, these attachments are actually In-Line parts. Rather than sending files as attachments, some mail clients will actually sent these 'attachments' as In-Line parts.
To reference these parts, use the MimeMessage.InLineParts collection. Another way to reference all attachments and in-line parts is too call the MimeMessageAttachmentInLineParts() method. This method will find every attachment + in-line part. Below is a code example to demonstrate this functionality.
string path = "c:\\temp\\sample.eml";
MimeMessage m = MimeMessage.ParseFile( path );
//get attachments and in-line parts
MimePartCollection mpc = m.AttachmentInLineParts();
Response.Write( "total parts: " + m.RetrieveAllParts().Count.ToString
//loop through the attachments+in-line parts, write out the name
foreach( MimePart mp in mpc)
{
Response.Write( mp.AttachmentName() );
}
As always, if anyone has any questions, feel free to email me using the Contact Us page.
Thanks,
Dave Wanta