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

Free Support Forum - aspose.com

Attachements still not recognized

using new aspose.email 1.2 documents still get mutulated by the fact that aspose is unable to recognize its attachements. I have attached an example for which aspose shows msg.attachement.count = 0. Linked resources = 1. Please advice

Please also view: <A href="https://forum.aspose.com/t/41459</A></P> <P>Sander van Haaff</P>

Hi Sander,


Thank you for sharing your sample file.

I have tested your file and you are right the attachment count is zero, if you load this message into an instance of MailMessage. But if you load the same message into an instance of MapiMessage then it shows the correct count (i.e. 1). Most probably the attachment in your shared sample file is embedded/in-line, that is why MailMessage is showing it as a LinkedResource (I’m still looking into it).

Please check the below source code for your reference. You can identify the attachment type and can also save it by using MapiMessage class.

C#
MapiMessage msg = MapiMessage.FromFile(“123.msg”);
foreach (MapiAttachment att in msg.Attachments)
{
if (att.Properties.Contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_A) || att.Properties.Contains(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
{
Console.WriteLine("Embedded, inline or linked Attachment File Name: " + att.LongFileName);
}
else
{
Console.WriteLine("Regular Attachment File Name: " + att.LongFileName);
}
att.Save(att.FileName);
}

Please feel free to write back in case you further queries or comments
Hi Babar,

You stated you are still looking into this problem. I have not heard from you, so perhaps you forgot? The file is not embedded (please look at the supplied attachment). Are you saying mapi is better/more stabile if we only use msg's? Indeed the attachments count on mapi shows 1, while the count on mailmessage is 0. When should we use mailmessage and when mapi?

I now implemented a "use mail message unless mapi had more attachements' kind of paradigm, but that is a workaround to solve a problem in aspose.email, so I 'd rather have you guys fix this ;-)

Kind regards,

Sander

Hi Sander,


I am sorry for the delayed response on this.

We had completed the investigation much earlier but forgot to post the reply. The sample message shared by you does not have an in-line attachment. I have verified that using my below source code. Also, I am able to extract the attachment using the MapiMessage Class.

C#
MapiMessage msg = MapiMessage.FromFile(“123.msg”);
foreach (MapiAttachment att in msg.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);
}
}

The MapiMessage class is a specialized class, built to work with only Outlook Message format(.msg). If working with Outlook messages from any Outlook version, the results produced with MapiMessage class would be more concrete. On the contrast, MailMessage is generic enabling you work with all email message formats (.msg,.eml,.mhtml).

I would suggest you to use MapiMessage class if your input/output is of .MSG format.