Loading and Saving Message

Detecting File Formats

Aspose.Email API provides the capability to detect the file format of the provided message file. The DetectFileFormat method of FileFormatUtil class can be used to achieve this.

The following classes and methods can be used to detect the loaded file format.

Loading a Message with Load Options

To load a message with specific load options, Aspose.Email provides the LoadOptions class that can be used as follow:

Preserving Embedded Message Format during Loading

Saving and Converting Messages

Aspose.Email makes it easy to convert any message type to another format. To demonstrate this feature, the code in this article loads three types of messages from disk and saves them back in other formats. The base class SaveOptions and the classes EmlSaveOptions, MsgSaveOptions, MhtSaveOptions, HtmlSaveOptions for additional settings when saving MailMessage can be used for saving messages to other formats. The article shows how to use these classes to save a sample email as EML format, Outlook MSG, MHTML format and HTML format. It also shows how to preserve the original email address.

Loading EML and Saving as EML

Loading EML and Saving as EML Preserving the Original Boundaries

Saving as EML Preserving TNEF Attachments

Loading EML, Saving to MSG

Saving as MSG with Preserved Dates

Saving MailMessage as MHTML

The following code sample loads an EML message into MailMessage and converts it to MHTML. Different options of MHTML can be used to obtain the desired results.

Converting to MHTML with Optional Settings

The MhtSaveOptions class provides additional options for saving email messages to MHTML format. The enumerator MhtFormatOptions makes it possible to write additional email information to the output MHTML. The following additional fields can be written:

WriteHeader – writes the email header to the output file. WriteOutlineAttachments – writes outline attachments to the output file. WriteCompleteEmailAddressToMht – writes the complete email address to the output file. WriteCompleteEmailAddress – writes the complete email address to the output file. HideExtraPrintHeader – hides extra print header from the top of the output file. WriteCompleteToEmailAddressToMht – writes the complete recipient email address to the output file. WriteCompleteFromEmailAddressToMht – writes the complete sender email address to the output file. WriteCompleteCcEmailAddressToMht – writes the complete email addresses of any carbon-copied recipients to the output file. WriteCompleteBccEmailAddressToMht – writes the complete email address of any blind carbon-copied recipients to the output file.

Rendering Calendar Events while Converting to MHTML

Aspose.Email API can render calendar events to the output MHTML file using the MhtFormatOptions Enumeration.

Exporting Email to MHT without Inline Images

Aspose.Email API can render calendar events to the output MHTML file using the MhtFormatOptions Enumeration.

Exporting Email to MHT with customized TimeZone

MailMessage class provides the setTimeZoneOffset method to set customized Timezone while exporting to MHT. The following code snippet shows you how to export the email to MHT with customized TimeZone.

Exporting Email to EML

The following code snippet shows you how to export emails to EML.

Saving Message as HTML

The HtmlSaveOptions class allows you to export the message body to HTML with the option to save embedded resources. The following code sample shows how to achieve this where the default value of EmbedResources is true.

Saving as HTML without Embedding Resources

Saving Message as Outlook Template (.oft) file

The following code snippet shows you how to save a message as an outlook template (.oft) file.