# Render email messages as HTML, PDF, PNG, and JPEG files Convert email messages to HTML, PDF, PNG, or JPEG using the GroupDocs.Viewer Python API. [GroupDocs.Viewer for Python via .NET](https://products.groupdocs.com/viewer/python-net) allows you to render your email messages in HTML, PDF, PNG, and JPEG formats. You do not need to use third-party email clients to view the contents of email files within your .NET application (web or desktop). To start with the GroupDocs.Viewer API, create a [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer) class instance. Pass an email message you want to view to the class constructor. You can load the message from a file or stream. Call one of the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method overloads to convert the loaded message to HTML, PDF, or image format. These methods allow you to render the entire message or specific pages. {{< button style="primary" link="https://products.groupdocs.app/viewer/email" >}} {{< icon "gdoc_person" >}} View email files online {{< /button >}} {{< button style="primary" link="https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-Python-via-.NET" >}} {{< icon "gdoc_github" >}} View demos and examples on GitHub {{< /button >}} ## Supported email file formats GroupDocs.Viewer supports the following email file formats: * [Email Message](https://docs.fileformat.com/email/eml) (.EML) * [Apple Mail Message](https://docs.fileformat.com/email/emlx) (.EMLX) * [Email Mailbox File](https://docs.fileformat.com/email/mbox/) (.MBOX) * [Outlook Message Item File](https://docs.fileformat.com/email/msg) (.MSG) * [vCard (Virtual Contact) File](https://docs.fileformat.com/email/vcf/) (.VCF, .VCARD) GroupDocs.Viewer can detect the email file format automatically based on information in the file header. ## Render email messages as HTML Create an [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions) class instance and pass it to the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert an email message to HTML. The `HtmlViewOptions` class properties allow you to control the conversion process. For instance, you can embed all external resources in the generated HTML file, minify the output file, and exclude specific fonts. Refer to the following documentation section for details: [Rendering to HTML]({{< ref "viewer/python-net/developer-guide/rendering-documents/rendering-to-html/_index.md" >}}). ### Create an HTML file with embedded resources To embed an email message in an HTML page, call the [HtmlViewOptions.for_embedded_resources](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) method and specify the output file name. {{< tabs "example1">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_email_to_html(): # Load email message with Viewer("sample.eml") as viewer: # Create an HTML file. viewOptions = HtmlViewOptions.for_embedded_resources("render_email_to_html/pdf_page_{0}.html") viewer.view(viewOptions) if __name__ == "__main__": render_email_to_html() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "pdf_page_1.html" >}} ```text HTML file (244 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-email-messages/render_email_to_html/pdf_page_1.html) {{< /tab >}} {{< /tabs >}} ### Create an HTML file with external resources To save an email message to a separate folder, call the [HtmlViewOptions.for_external_resources](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) method and pass the following parameters: * The output file path format * The path format for the folder with external resources * The resource URL format {{< tabs "example2">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_email_to_html_external(): # Load email message with Viewer("sample.eml") as viewer: # Specify the HTML file name and location of external resources. # {0} is replaced with the resource name in the output file name. # The resource URL is relative to the HTML file. viewOptions = HtmlViewOptions.for_external_resources("render_email_to_html_external/pdf_page_{0}.html", "render_email_to_html_external/pdf_page_{0}/resource_{0}_{1}", "pdf_page_{0}/resource_{0}_{1}") viewer.view(viewOptions) if __name__ == "__main__": render_email_to_html_external() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-email-to-html-external-outputs.zip" >}} ```text render_email_to_html_external/pdf_page_1.html (15 KB) render_email_to_html_external/pdf_page_1/resource_1_f.ttf (54 KB) render_email_to_html_external/pdf_page_1/resource_1_f1.ttf (36 KB) render_email_to_html_external/pdf_page_1/resource_1_f2.ttf (45 KB) render_email_to_html_external/pdf_page_1/resource_1_f3.ttf (32 KB) render_email_to_html_external/pdf_page_1/resource_1_i.png (3 KB) render_email_to_html_external/pdf_page_1/resource_1_s.css (3 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-email-messages/render_email_to_html_external/render-email-to-html-external-outputs.zip) {{< /tab >}} {{< /tabs >}} External resources are placed in a separate folder. ## Render email messages as PDF Create a [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions) class instance and pass it to the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert an email message to PDF. The `PdfViewOptions` class properties allow you to control the conversion process. For instance, you can protect the output PDF file, reorder its pages, and specify the quality of document images. Refer to the following documentation section for details: [Rendering to PDF]({{< ref "viewer/python-net/developer-guide/rendering-documents/rendering-to-pdf/_index.md" >}}). {{< tabs "example3">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions def render_email_to_pdf(): # Load email message with Viewer("sample.eml") as viewer: # Create a PDF file. viewOptions = PdfViewOptions("render_email_to_pdf/email_message.pdf") viewer.view(viewOptions) if __name__ == "__main__": render_email_to_pdf() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "email_message.pdf" >}} ```text Binary file (PDF, 112 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-email-messages/render_email_to_pdf/email_message.pdf) {{< /tab >}} {{< /tabs >}} ## Render email messages as PNG Create a [PngViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions) class instance and pass it to the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert an email message to PNG. Use the [PngViewOptions.height](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/#properties) and [PngViewOptions.width](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/#properties) properties to specify the output image size in pixels. {{< tabs "example4">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PngViewOptions def render_email_to_png(): # Load email message with Viewer("sample.eml") as viewer: # Create a PNG file for each page. # {0} is replaced with the current page number in the file name. viewOptions = PngViewOptions("render_email_to_png/email_page_{0}.png") # Set width and height. viewOptions.width = 800 viewOptions.height = 1000 viewer.view(viewOptions) if __name__ == "__main__": render_email_to_png() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-email-to-png-outputs.zip" >}} ```text render_email_to_png/email_page_1.png (159 KB) render_email_to_png/email_page_2.png (42 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-email-messages/render_email_to_png/render-email-to-png-outputs.zip) {{< /tab >}} {{< /tabs >}} ## Render email messages as JPEG Create a [JpgViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions) class instance and pass it to the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert an email message to JPEG. Use the [JpgViewOptions.height](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/#properties) and [JpgViewOptions.width](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/#properties) properties to specify the output image size in pixels. {{< tabs "example5">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import JpgViewOptions def render_email_to_jpg(): # Load email message with Viewer("sample.eml") as viewer: # Create a JPG file for each page. # {0} is replaced with the current page number in the file name. viewOptions = JpgViewOptions("render_email_to_jpg/email_to_jpg_{0}.jpg") # Set width and height. viewOptions.width = 800 viewOptions.height = 1000 viewer.view(viewOptions) if __name__ == "__main__": render_email_to_jpg() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-email-to-jpg-outputs.zip" >}} ```text render_email_to_jpg/email_to_jpg_1.jpg (114 KB) render_email_to_jpg/email_to_jpg_2.jpg (36 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-email-messages/render_email_to_jpg/render-email-to-jpg-outputs.zip) {{< /tab >}} {{< /tabs >}} ## Specify rendering options GroupDocs.Viewer supports the [EmailOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/emailoptions) class that allows you to specify different options for rendering email messages. To access these options, use the [EmailOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/baseviewoptions/#properties) property for one of the following classes (depending on the output file format): * [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions) * [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions) * [PngViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions) * [JpgViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions) ### Set the output page size GroupDocs.Viewer allows you to specify page size for the output file when you convert an email message to HTML, PDF, or image format. Assign a [PageSize](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pagesize/) enumeration member to the [email_options.page_size](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/emailoptions/#properties) property to select one of the predefined page sizes (UNSPECIFIED, LETTER, LEDGER, A0, A1, A2, A3, or A4). The following example specifies page size for the output PDF file: {{< tabs "example6">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions, PageSize def render_email_with_page_size(): # Load email message with Viewer("sample.eml") as viewer: # Create a PDF file. viewOptions = PdfViewOptions("render_email_with_page_size/email_with_page_size.pdf") # Specify the page size. viewOptions.email_options.page_size = PageSize.A4 viewer.view(viewOptions) if __name__ == "__main__": render_email_with_page_size() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "email_with_page_size.pdf" >}} ```text Binary file (PDF, 112 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-email-messages/render_email_with_page_size/email_with_page_size.pdf) {{< /tab >}} {{< /tabs >}} ### Specify the date and time format and change the time zone When rendering email messages, GroupDocs.Viewer formats date and time information in the message header based on the system's date and time settings. If you want to change the default date and time format or specify the time zone offset, use the following properties: * [email_options.date_time_format](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/emailoptions/#properties)---Allows you to define a custom date and time format. See the following topics for details: * [Standard date and time format strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) * [Custom date and time format strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) * [email_options.time_zone_offset](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/emailoptions/#properties)---Specifies the hours and minutes offset from UTC. The offset is displayed with a leading sign. A plus sign (+) indicates time ahead of UTC, and a minus sign (-) indicates time behind UTC. {{< tabs "example8">}} {{< tab "Python" >}} ```python from datetime import timedelta from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_email_with_datetime_format(): # Load email message with Viewer("sample.eml") as viewer: # Create an HTML file. options = HtmlViewOptions.for_embedded_resources("render_email_with_datetime_format/email_with_datetime_format.html") # Apply a custom format to the date in the email message header. options.email_options.date_time_format = "MM d yyyy HH:mm tt zzz" # Specify the time zone offset. options.email_options.time_zone_offset = timedelta(hours=1) viewer.view(options) if __name__ == "__main__": render_email_with_datetime_format() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "email_with_datetime_format.html" >}} ```text HTML file (244 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-email-messages/render_email_with_datetime_format/email_with_datetime_format.html) {{< /tab >}} {{< /tabs >}}