Skip to end of metadata
Go to start of metadata
Contents Summary
  

Aspose.Email can create Outlook message (MSG) files. The MailMessage class has a save() method that can save the Outlook MSG file to disk or stream. The code snippet below creates an instance of the MailMessage class and set properties like from, to, subject, body, before saving it.

Creating and Saving an MSG file

To create and save an MSG file:

  1. Creates a new instance of the MailMessage class and set properties such as from, to, subject and body.
  2. Call the MapiMessage class' fromMailMessage() method which accepts the object of the MailMessage.
  3. Use the fromMailMessage() method to convert the MailMessage into MapiMessage (MSG).
  4. 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

The following code snippet shows the use of MailMessage and MapiMessage classes to save the email in MSG file

 

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:

  1. Create an instance of the MailMessage class.
  2. Set the MailMessage object's properties like the subject, body, from, to and CC.
  3. Create an instance of the MapiMessage class.
  4. Load a MailMessage instance in the MapiMessage object using the MapiMessage class' fromMailMessage() method.
  5. Set the message flags using the MapiMessage class' setMessageFlags() method.
  6. 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.

Smaller Size

 

Faster

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.

Labels
  • No labels