Managing Outlook Messages
Save Emails as HTML
Aspose.Email makes it possible to save the email resources with relative paths when exporting the messages to the HTML format. This gives more flexibility in how the resources are linked in the output HTML file, making it easier to share and display the saved emails on different systems.
To save the resources with relative paths, use the use_relative_path_to_resources property of the HtmlSaveOptions class. The default value is False, which means the resources are saved with absolute paths. When it is set to True, the resources are saved with relative paths.
HTML files with relative paths are more portable and can be viewed correctly regardless of the file structure of the hosting environment.
The following code sample demonstrates how to save an email with the relative path to resources:
import aspose.email as ae
from aspose.email.mapi import MapiMessage
msg = MapiMessage.load(data_dir + "message.msg")
html_save_options = ae.HtmlSaveOptions()
html_save_options.resource_rendering_mode = ae.ResourceRenderingMode.SAVE_TO_FILE
html_save_options.use_relative_path_to_resources = True
msg.save(data_dir + "message.html", html_save_options)
In this case, the resources are saved in the [html file name]_files folder next to the .html file, and the HTML references them through relative paths.
The code sample below demonstrates how to save with the absolute path to resources:
import aspose.email as ae
from aspose.email.mapi import MapiMessage
msg = MapiMessage.load(data_dir + "message.msg")
html_save_options = ae.HtmlSaveOptions()
html_save_options.resource_rendering_mode = ae.ResourceRenderingMode.SAVE_TO_FILE
html_save_options.use_relative_path_to_resources = False
msg.save(data_dir + "message.html", html_save_options)
As in the first case, the resources are saved in the [html file name]_files folder by default, but the HTML references them through absolute paths.
ResourceHtmlRendering event. That API relies on .NET delegates and is not exposed in Aspose.Email for Python via .NET.
MSG to EML Conversion Preserving the RTF Body
The conversion of an MSG file to EML preserving the RTF body can be done in two ways:
- through the
preserve_rtf_contentproperty of the MsgLoadOptions class; - through the
preserve_rtf_contentproperty of the MailConversionOptions class.
Both properties get or set a value indicating whether the RTF body is kept in the resulting MailMessage.
The following code snippets show how to convert an MSG file to EML and preserve the RTF body:
import aspose.email as ae
load_options = ae.MsgLoadOptions()
load_options.preserve_rtf_content = True
eml = ae.MailMessage.load(data_dir + "my.msg", load_options)
from aspose.email.mapi import MapiMessage, MailConversionOptions
conversion_options = MailConversionOptions()
conversion_options.preserve_rtf_content = True
msg = MapiMessage.load(data_dir + "my.msg")
eml = msg.to_mail_message(conversion_options)
See Also
- Working with MAPI Properties — read, set and remove MAPI properties, convert MSG to MIME and set conversion timeouts.
- Managing Digital Signatures — sign, verify, decrypt and unsign Outlook messages.
- Converting and Processing Outlook Templates (OFT) — work with .oft template files.