Free Support Forum - aspose.com

Extracting images from email body

Hello

I am using Aspose.Network.Pop3 and wanted to save images pasted into email bodies into a file on disk. How can I do this? The image(s) aren't attachments, they are base 64 encoded into the mail message itself. Does Aspose have a method to extract these easily or do I need to open the .EML file and load an object with the base 64 data, convert, and write to disk? A code snippet would be helpful...

Thanks

Mike


This message was posted using Page2Forum from MailMessage Properties - Aspose.Network for .NET

Hello, Mike,

Do you have chance to check the linkedresources property of the MailMessage? You can load the eml file into a MailMessage class, then get the linked images from the linkedresources collection. Could you provide me a sample eml file to test about it?

Thanks a lot

Attached is an .EML file with an embedded picture. I would like to see C# code to extract it using the LinkedResources collection.

Thanks

Mike

Hi Mike,

The following sample code can extract and save the embedded picture from the eml file.

MailMessage msg = MailMessage.Load("c:\\temp\\email.eml");

foreach (LinkedResource resource in msg.LinkedResources)

{

// save the attachment to some folder. Filename comes from resource.Name

resource.Save("c:\\temp\\" + resource.Name);

}