This technical tip shows how to Read Embedded Email Attachments from Message. Sometimes, we get emails that have other emails embedded in them as an attachment. These embedded emails are complete messages having their own Recipients list, Subject, Body and Attachments. Furthermore, each of these messages can have embedded messages in them.
Using Aspose.Email Java API, the developers can access each embedded message as an individual message. We will elaborate such example using recursive functionality.
Steps to Access Embedded Messages from an existing Email Message
Please perform the following sequence of steps:
Create an instance of MailMessage class
Load the existing Email Message using the load() method exposed by MailMessage class and by specifying the correct MessageFormat.
Call Recursive method by passing the instance of MailMessage class as parameter.
Iterate over the attachment collection of MailMessage Instance.
Replace the invalid chars from Attachment name and restrict the name to 50 chars.
Save the attachment to disk using save() method exposed by Attachment class.
Create an instance of MailMessage class
Load the existing Email Message using the load() method exposed by MailMessage class and by specifying the correct MessageFormat.
Call Recursive method by passing the instance of MailMessage class as parameter.
Repeat 1 – 6.
Sample Code for Reading Embedded Email Attachments using Aspose.Email for Java [Java]
// Base folder to load and save files used in this demo
// Call the function recursively to parse this message and attachments
ParseMessage(attMsg);
}
}
}
Overview: Aspose.Email for Java
Aspose.Email for Java is a Non-Graphical Java component that enables Java applications to read and write MS Outlook MSG files from within a Java application without using MS Outlook. It enables developers to create new MSG file from scratch, update an existing MSG file, read Outlook MSG file & get its properties like subject, body, recipients in to, cc and bcc, adding or removing attachment, sender information & MAPI properties. Aspose.Email can be used with Web as well as Desktop Application.