We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Distinguish between embedded and file attachments in html emails

Hi,

i have some problems in processing attachments. I want to distinguish between embedded attachments (like graphics etc.) and file attachments.

Is use the attachment properties PR_ATTACH_CONTENT_ID_A and PR_ATTACH_CONTENT_ID_W to detect embedded attachments.

The code looks like this

public static void AttachmentTest()
{
string strFileName = “c:\temp\HtmlMail2.msg”;

Console.WriteLine(string.Format(“Processing mail {0} …”, strFileName));

MapiMessage msg = MapiMessage.FromFile(strFileName);

foreach (MapiAttachment attach in msg.Attachments)
{
if (attach.Properties.Contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_A) || attach.Properties.Contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
{
Console.WriteLine(string.Format(“Embedded Attachment {0}”, attach.DisplayName));
}
else
{
Console.WriteLine(string.Format(“Attached File {0}”, attach.DisplayName));
}
}
msg = null;
}

If i run the code with the attached Html-Mail then all attachment are identified as embedded. The displayname of the attached file is empty. If i open the mail with MS Outlook 2010 then outlook shows the attched file SKMBT_C45111072510081.pdf.

.net runtime 2.0
Aspose.Email 1.1.0.0

Best regards, Martin

internal bugid#4337

Hi,


Thank you for your inquiry.

We have logged an investigative ticket (id: 32220) in our tracking system to look further into this issue. As soon as we receive any updates we will post them here for your reference.

We apologize for your inconvenience.

Hi,


Thank you for your patience.

Please check the below source code for your reference. You can use it with latest version of Aspose.Email for .NET v1.3.0.

C#

var mapi = MapiMessage.FromFile(“HTMLMail2.msg”);
foreach (var att in mapi.Attachments)
{
if (att.Properties.Contains(0x7FFD0003) && att.Properties[0x7FFD0003].GetInt32() == 8)
{
Console.WriteLine("Embedded, inline or linked Attachment File Name: " + att.LongFileName);
}
else
{
Console.WriteLine("Regular Attachment File Name: " + att.LongFileName);
}
}

Please also note that, with the release of Aspose.Email for .NET v1.4.0 [scheduled in last quarter of January 2012], you will be able to use the enumeration MapiPropertyTag.PR_ATTACHMENT_FLAG instead of value 0x7FFD0003.
Hello Babar,

somehow thats not working for me to distinguish those attachments.

however this works for me:

C#
var mapi = MapiMessage.FromFile("HTMLMail2.msg"); foreach (var att in mapi.Attachments) { if (mapi.BodyHtml.Contains(att.DisplayName)) { Console.WriteLine("Embedded, inline or linked Attachment File Name: " + att.LongFileName); } else {
Console.WriteLine("Regular Attachment File Name: " + att.LongFileName); } }

with regards,

Jitte Dooper

Hi Jitte,


Thank you for providing your solution to this problem. I have checked the sample source and it seems to work for all embedded images.

I really appreciate your help in this.