Extract Inline Images from an EML Email Message

Hi,


I am evaluating the Aspose.Email to import eml files into our system, and was wondering if there is a way I can get the inline(embedded) images so that I can save them on file?

This message was posted using Email2Forum by Babar Raza.

Hi Miguel,

Thank you for considering Aspose.Email.

The inline images in an email message are contained in the Linked Resources collection of the message. You can use the following sample code for this purpose. Please feel free to write to us in case you have any other inquiry in this regard. Also, please download and use the latest version of Aspose.Email for .NET 4.5.0 which is the latest version of our API till yet.

Sample Code:

MailMessage eml = MailMessage.Load(“MailMessage.eml”);

foreach (LinkedResource lr in eml.LinkedResources)

lr.Save(lr.ContentType.Name);

eml.Dispose();

Hi,


I have tried the sample code but the “LinkedResources” in my example is empty. I have also installed the latest version of Aspose.Mail, 4.5.0.

I am attaching my sample .eml file for your testing.

Thank You

Hi Miguel,


Thank you for providing the feedback.

In this sample, the linked resources are contained within the alternate view of the EML file. You can use the sample code below to retrieve information about these linked resources. Please let us know if we can be of any additional help to you in this regard:

Sample Code:


string dir = “571424\”;


MailMessage eml = MailMessage.Load(dir + “toest 2.eml”);


foreach (AlternateView av in eml.AlternateViews)

{

if (av.LinkedResources.Count > 0)

{

foreach (LinkedResource lr in av.LinkedResources)

Console.WriteLine(lr.ContentType.Name);

}

}


That works fine. Thank you.

Would it not be a good idea to have a collection specifically for inline/embedded images or whatever other object can be embedded?

Hi Miguel,


Linked resources can be attached to a particular alternate view of EML or directly to EML. If these are present under main EML, the first sample demonstrating extraction of these resources from MailMessage.LinkedResources can be used. Otherwise if resources are linked to a particular view in the EML(similar to your sample EML), you may please use the last sample code shared with you which is using AlternateView.LinkedResources.

Please feel free to write us back if you have any other query in this regard.