Skip to main content

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

Project description

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==--

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

html2eml-0.0.5.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

html2eml-0.0.5-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file html2eml-0.0.5.tar.gz.

File metadata

  • Download URL: html2eml-0.0.5.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for html2eml-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6461b73ef844be83b402360f216e476298ba7c88d0b844bb3acd579aa8db4b84
MD5 091b938a4431cf2d796a9678cea549f3
BLAKE2b-256 b52bd0f984ee6a0d151a278cb926431888e09c410c756045c5b8ba4731d8e415

See more details on using hashes here.

File details

Details for the file html2eml-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: html2eml-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for html2eml-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 124378f2f11ea4f8fccaf0c927f317b6e826bf470dc9937b005f0c9f5d22fb66
MD5 b4598c374e3b372d3c21311c976590fb
BLAKE2b-256 cc2e224cabe2bc3d58a902d17744e45c7e13303c2d0ad3059fa5acecdc14f7c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page