Hi Iqbal,
Please use this code snipet and see the output of the images not extracting properly.
Please use the first attachment of this email chain. I have attached as a .zip extension. Please renmae to .msg of the attachment and try this sample code below
If there is any changes need to work properly of this below code please let me know.
In my sampel attachment is not working. Please try my attachmed sample .zip file.
static void ExtractInlineImages()
{
int count;
string dir = @"C:\Email\Test\";
var message = Aspose.Email.Outlook.MapiMessage.FromFile(@"C:\Email\InBox\FW Claim # 026172514Hartford # SBB403675.msg");
var attachments = message.Attachments;
count = attachments.Count;
Console.WriteLine("Total attachments " + count);
for (int i = 0; i < attachments.Count; i++)
{
var attachment = attachments[i];
if (IsInlineAttachment(attachment, message.BodyType))
{
Console.WriteLine(attachment.LongFileName + " is inline attachment");
attachment.Save(dir + attachment.LongFileName);
}
}
}
static bool IsInlineAttachment(Aspose.Email.Outlook.MapiAttachment att, Aspose.Email.Outlook.BodyContentType messageBodyType)
{
switch (messageBodyType)
{
case Aspose.Email.Outlook.BodyContentType.PlainText:
// ignore indications for plain text messages
return false;
case Aspose.Email.Outlook.BodyContentType.Html:
// check the PidTagAttachFlags property
if (att.Properties.Contains(0x37140003))
{
long? attachFlagsValue = att.GetPropertyLong(0x37140003);
if (attachFlagsValue != null && (attachFlagsValue & 0x00000004) == 0x00000004)
{
// check PidTagAttachContentId property
if (att.Properties.Contains(Aspose.Email.Outlook.MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
att.Properties.Contains(Aspose.Email.Outlook.MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
{
return true;
}
// check PidTagAttachContentId property
if (att.Properties.Contains(Aspose.Email.Outlook.MapiPropertyTag.PR_ATTACH_CONTENT_ID) ||
att.Properties.Contains(Aspose.Email.Outlook.MapiPropertyTag.PR_ATTACH_CONTENT_ID_W))
{
return true;
}
// check PidTagAttachContentLocation property
if (att.Properties.Contains(0x3713001E) ||
att.Properties.Contains(0x3713001F))
{
return true;
}
}
}
else if ((att.Properties.Contains(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline")
|| (att.Properties.Contains(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline"))
{
return true;
}
return false;
case Aspose.Email.Outlook.BodyContentType.Rtf:
// If the body is RTF, then all OLE attachments are inline attachments.
// OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property
if (att.Properties.Contains(Aspose.Email.Outlook.MapiPropertyTag.PR_ATTACH_METHOD))
{
return att.GetPropertyLong(Aspose.Email.Outlook.MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006;
}
return false;
default:
throw new ArgumentOutOfRangeException();
}
}
Thanks
P. Saravanan.