Creating and Saving an MSG file
To create and save an MSG file:
- Creates a new instance of the MailMessage class and set properties such as from, to, subject and body.
- Call the MapiMessage class' fromMailMessage() method which accepts the object of the MailMessage.
- Use the fromMailMessage() method to convert the MailMessage into MapiMessage (MSG).
- Calls the MapiMessage.save() method to save the MSG file.
If you open the saved file in Microsoft Outlook, it will look like the screenshot below.
Figure: The saved email message
Save Message as Draft
A draft is an unfinished message that has not yet been sent, instead, it is stored in a separate folder for future use. With Aspose.Email for Java, programmers can create a message using the MailMessage class and store it on disk using the MapiMessage class.
Draft email messages are always in Outlook (MSG) format.
To save a draft email:
- Create an instance of the MailMessage class.
- Set the MailMessage object's properties like the subject, body, from, to and CC.
- Create an instance of the MapiMessage class.
- Load a MailMessage instance in the MapiMessage object using the MapiMessage class' fromMailMessage() method.
- Set the message flags using the MapiMessage class' setMessageFlags() method.
- Save the message to disk in Outlook format using the MapiMessage class' save() method.
Implications of Body Compression
The RTF body compression method can be used to generate a smaller size MSG. However, this results in slower speed. To creating messages with improved speed, set the flag to false. This flag, in turn, has an effect on the created PSTs: smaller MSG files result in smaller PST, and large MSG files result in slower PST creation.
Preserving Original Email Address
Status of Recipients from a Meeting Request
Converting EML to MSG Preserving Embedded EML format
EML files can be loaded into MapiMessage class by instantiating a MailMessage object and passing it to MapiMessage.FromMailMessage method. If the EML file contains embedded EML files, use MapiConversionOptions.setPreserveEmbeddedMessageFormat to retain the format of embedded EML files. The below code snippet shows how to load EML files into MapiMessage while preserving the format of embedded EML files.