Loading and Saving Message

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.

The following code snippet shows you how to detecting file formats.

Loading a Message with Load Options

The following code snippet shows you how to load a message with load options.

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.
  • HTML format.

Load and Save an EML message

The following code snippet shows you how to load an EML message and saves it to the disc in the same format.

Load and Save an EML message Preserving the Original Boundaries

The following code snippet shows you how to load EML and save as EML preserving the original boundaries.

Saving as EML Preserving TNEF Attachments

The following code snippet shows you how to save as EML preserving TNEF attachments.

Save EML as MSG

The following code snippet shows you how to loads an EML message and converts it to MSG using the appropriate option from SaveOptions.

Saving as MSG with Preserved Dates

The MsgSaveOptions class allows you to save the source message as an Outlook Message file (MSG) preserving dates. The following code snippet shows you how to Saving as MSG with Preserved Dates.

Saving MailMessage as MHTML

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

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 – write the email header to the output file.
  • WriteOutlineAttachments – write outline attachments to the output file.
  • WriteCompleteEmailAddress – write the complete email address to the output file.
  • NoEncodeCharacters – no transfer encoding of characters should be used.
  • HideExtraPrintHeader – hide extra print header from the top of the output file.
  • WriteCompleteToEmailAddress – write the complete recipient email address to the output file.
  • WriteCompleteFromEmailAddress – write the complete sender email address to the output file.
  • WriteCompleteCcEmailAddress – write the complete email addresses of any carbon-copied recipients to the output file.
  • WriteCompleteBccEmailAddress – write the complete email address of any blind carbon-copied recipients to the output file.
  • RenderCalendarEvent – write text from the calendar event to the output file.
  • SkipByteOrderMarkInBody – write Byte Order Mark(BOM) bytes to the output file.
  • RenderVCardInfo – write text from VCard AlternativeView to the output file.
  • DisplayAsOutlook – display From header.
  • RenderTaskFields – writes specific Task fields to the output file.
  • None – No setting specified.

The following code snippet shows you how to convert EML files to MHTML with optional settings.

Rendering Calendar Events while Converting to MHTML

The MhtFormatOptions.RenderCalendarEvent renders the Calendar events to the output MTHML. The following code snippet shows you how to render calendar events while converting to MHTML.

Exporting Email to MHT without Inline Images

Exporting Email to MHT with customized TimeZone

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

Changing Font while Converting to MHT

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. The following code snippet shows you how to Save Message as HTML.

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.