1. Products
  2.   Email
  3.   Python
  4.   Python-Emails

Free Python API to Create, Load & Send HTML Emails

Open Source Python Library for Emails Loading, Sending, Receiving, & Tracking with attachments. It allows Load message from URL or from File.

In today's digital world, email communication plays a vital role in various domains, ranging from personal communication to business correspondence. Python, being a versatile programming language, provides developers with numerous libraries to handle email-related tasks efficiently. One such powerful open source library is python-emails, which simplifies email handling, parsing, and generation inside Python applications. The library offers a straightforward and intuitive API, making it easy to work with email messages and attachments.

Python-Emails is a versatile and user-friendly open source library that simplifies email handling tasks and has included a bunch of features for working with email messages, such as Creating new email messages from scratch, parsing email messages effortlessly, generating emails with HTML content, conversion between HTML and plain text, email attachments support, dynamically generate email content based on templates, handles MIME (Multipurpose Internet Mail Extensions) emails, handling email messages with multi-parts and many more.

Python-Emails is a very powerful open source library that provides a simple and intuitive interface for handling email messages. It aims to simplify email handling tasks, such as parsing email content, generating new emails, and modifying existing ones. Built on top of the standard library's email module, python-emails extends its functionality while offering a more user-friendly API. By leveraging Python-Emails, you can streamline your email-related tasks and focus on delivering robust and efficient applications. Its intuitive API and support for templating make it an excellent choice for software developers looking to enhance their email automation and communication processes.

Previous Next

Getting Started with Python-Emails

The easiest way to install Python-Emails is via pypi. Please first you need to download it and then can easily install it using the following command for easy installation.

Install Python-Emails via PyPi

 pip install emails 
You can also download it directly from Python-Emails.

Create New Email Message via Python API

The open source Python-Emails library enables Python developers to generate and send email messages inside their own applications. Creating new email messages becomes a breeze with easy to use interface of python-emails library. It offers an easy-to-use API to compose emails by specifying the sender, recipients, subject, body, and attachments. The library abstracts away the low-level details, allowing users to focus on the content and structure of the email rather than the intricacies of email formatting. The following example shows how software developers can create and send new email messages using Python code.

Create Email Messages using Python API

# create message:

import emails
message = emails.html(html=open('letter.html'),
                      subject='Friday party',
                      mail_from=('Company Team', 'contact@mycompany.com'))

# Send and get response from SMTP server

r = message.send(to=('John Brown', 'jbrown@gmail.com'),
                 render={'name': 'John'},
                 smtp={'host':'smtp.mycompany.com', 'port': 465, 'ssl': True, 'user': 'john', 'password': '***'})
assert r.status_code == 250

Manage Emails with Attachments via Python

The Python-Emails library makes it easy for software programmers to send emails message with attachments inside Python applications. Dealing with email attachments is made effortless by the open source python-emails library. It allows software developers to add attachments to their emails by specifying the file path or providing the content directly. Furthermore, it enables programmers to extract attachments from incoming emails, facilitating easy processing of file attachments in your workflows. The following example demonstrates how software developers can attach files or inline images with just a couple of lines of Python code.

How to Attach Files or Inline Images inside Python Applications?

message.attach(data=open('event.ics', 'rb'), filename='Event.ics')
message.attach(data=open('image.png', 'rb'), filename='image.png',

Sending Emails using Templates via Python

The open source Python-Emails library has included a very powerful feature for sending email message using the build-in templates inside Python applications. The library integrates well with popular templating engines like Jinja2, enabling software developers to dynamically generate email content based on templates. This feature is particularly useful when sending personalized emails or generating automated email notifications, as it simplifies the process of merging data with email templates. The following example shows how software developers can send email messages using temples via Python commands.

Send Email Messages using Templates via Python API

from emails.template import JinjaTemplate as T

message = emails.html(subject=T('Payment Receipt No.{{ billno }}'),

Dear {{ name }}! This is a receipt...'), mail_from=('ABC', 'robot@mycompany.com')) message.send(to=('John Brown', 'jbrown@gmail.com'), render={'name': 'John Brown', 'billno': '141051906163'})