Skip to main content

html2eml

Build Status MIT License badge

html2eml is a simple package for converting HTML text to EML format (MIME RFC 2822).

Getting started

Create simple message with to and from headers

>>> import html2eml

>>> msg = html2eml.from_html('<html><body><p>Hello world</p></body></html>', to='spam@example.com', from_='eggs@example.com', subject='Sausage')

>>> print(msg.as_string())
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
To: spam@example.com
From: eggs@example.com
Subject: =?utf-8?q?Sausage?=

PGh0bWw+PGJvZHk+PHA+SGVsbG8gd29ybGQ8L3A+PC9ib2R5PjwvaHRtbD4=

html2eml allows changing charset of html message

>>> msg = html2eml.from_html('<html><body><p>Hello world</p></body></html>', charset='ISO-8859-1', to='spam@example.com')

>>> print(msg.as_string())
MIME-Version: 1.0
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
To: spam@example.com

<html><body><p>Hello world</p></body></html>

Outside of To and From fields we can also specify CC and BCC

>>> msg = html2eml.from_html('<html><body><p>Hello world</p></body></html>', to='foo@example.com', from_='bar@example.com', cc='spam@example.com', bcc='eggs@example.com')

>>> print(msg.as_string())
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
To: foo@example.com
From: bar@example.com
CC: spam@example.com
BCC: eggs@example.com

PGh0bWw+PGJvZHk+PHA+SGVsbG8gd29ybGQ8L3A+PC9ib2R5PjwvaHRtbD4=

In case of multiple recipients we can pass a list in any of those fields

>>> msg = html2eml.from_html('<html><body><p>Hello world</p></body></html>', to=['foo@example.com', 'spam@example.com', 'eggs@example.com'], from_='bar@example.com')

>>> print(msg.as_string())
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
To: foo@example.com, spam@example.com, eggs@example.com
From: bar@example.com

PGh0bWw+PGJvZHk+PHA+SGVsbG8gd29ybGQ8L3A+PC9ib2R5PjwvaHRtbD4

Library also supports converting plain EML messages to MIME Multipart messages

>>> msg = html2eml.from_html('<html><body><p>Hello world</p></body></html>', to=['foo@example.com', 'spam@example.com', 'eggs@example.com'], from_='bar@example.com')

>>> multipart = html2eml.convert_eml_to_multipart(msg)

>>> print(multipart.as_string())
MIME-Version: 1.0
Content-Type: multipart/mixed; charset="utf-8"; boundary="===============2813024326530809151=="
Content-Transfer-Encoding: base64
To: foo@example.com, spam@example.com, eggs@example.com
From: bar@example.com

--===============2813024326530809151==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

PGh0bWw+PGJvZHk+PHA+SGVsbG8gd29ybGQ8L3A+PC9ib2R5PjwvaHRtbD4=

--===============2813024326530809151==--

Metadata

Release files for html2eml 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for html2eml 0.0.5
File Size Uploaded
html2eml-0.0.5.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for html2eml 0.0.5
File Interpreter ABI Platform
html2eml-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 kB

Release files / html2eml-0.0.5.tar.gz

Download URL html2eml-0.0.5.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6461b73ef844be83b402360f216e476298ba7c88d0b844bb3acd579aa8db4b84
BLAKE2b-256 checksum
How to use checksums
b52bd0f984ee6a0d151a278cb926431888e09c410c756045c5b8ba4731d8e415
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release files / html2eml-0.0.5-py3-none-any.whl

Download URL html2eml-0.0.5-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
124378f2f11ea4f8fccaf0c927f317b6e826bf470dc9937b005f0c9f5d22fb66
BLAKE2b-256 checksum
How to use checksums
cc2e224cabe2bc3d58a902d17744e45c7e13303c2d0ad3059fa5acecdc14f7c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.2

1 release file

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page