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

Free Support Forum - aspose.com

Inline image not detected via PR_ATTACHMENT_FLAGS property in MapiMessage class


I have a requirement to remove all genuine attachments from .msg files in order to save the original email.
I need to detect inline images (embedded attachments) and not remove this from the original email as they are not genuine attachments. By inline images I mean things like email signatures and email footers etc.

I have been using the following code to detect inline images for .msg files however its not working for a particular sample file that I have attached to this post.

The picture at the bottom of the email (which comes as an email signature) is not being detected as an inline image, also its LongFileName is null. Please treat the attached sample file as confidential.

Following is the code that I am using to detect inline images as advised in How to Identify Embbed Images from Attachment.

NOTE: I’m using Aspose Email for Java 2.8.0.

MapiMessage origMessage = MapiMessage.fromFile(“inline image test.msg”);
MapiAttachmentCollection attachments = origMessage.getAttachments();
int count = attachments.size();
System.out.println("Total attachments " + count);
for (int i = count - 1; i >= 0; --i)
MapiAttachment attachment = (MapiAttachment) attachments.get(i);
//check if attachment is inline
if (attachment.getMyProperties().contains(MapiPropertyTag.PR_ATTACHMENT_FLAGS) && attachment.getMyProperties().get(MapiPropertyTag.PR_ATTACHMENT_FLAGS).getInt32() == 8)
//Save inline/embedded attachments
System.out.println("Preserved " + attachment.getLongFileName());
//delete regular attachments
System.out.println("Deleted " + attachment.getLongFileName());
FileOutputStream fileOut = new FileOutputStream(“output.msg”);


Sorry I also have a second question for this post.

What is the equivalent way to detect inline images from the MailMessage class for .eml file?


Hi Chamindu,

Thank you for writing to us.

In order to differentiate between Inline and Regular attachments, I would request you to please have a look at our technical article Differentiating between Inline and Regular Attachments. I have tested your attachment file with it and it reports the image as inline attachment.

In order to do the same for MailMessage, you can extract the inline images from a message file using LinkedResources of the message. Please let us know if we can be of any additional help to you.

Java Code Sample:

MailMessage msg = MailMessage.load(“Inline Image

LinkedResourceCollection lrc = msg.getLinkedResources();

for (int i=0; i< lrc.size(); i++)


LinkedResource lr = (LinkedResource)lrc.get(i);


if (lr.getContentType().getMediaType().equals("image/bmp"))

lr.save(lr.getContentId() + ".bmp");