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.

What is Python-Emails Library?

In today's digital landscape, efficient email communication is vital across both personal and business domains. For developers using Python, a versatile and powerful programming language, the python-emails library emerges as an essential open source tool for handling email-related tasks. This library simplifies complex processes like email parsing, generation, and management within Python applications by offering a straightforward and intuitive API. Built upon the standard library's email module, python-emails extends its functionality, making it easier to work with email messages and attachments without sacrificing power for simplicity.

Python-Emails is a versatile and feature-rich open source library designed to streamline all aspects of email handling. It supports a wide range of essential functions, including creating new email messages from scratch, effortlessly parsing incoming messages, and generating emails with rich HTML content. Key capabilities such as seamless conversion between HTML and plain text, robust email attachment support, and dynamic content generation using templates empower developers to build sophisticated email automation. Additionally, the library expertly handles MIME (Multipurpose Internet Mail Extensions) emails and manages messages with multiple parts, ensuring reliable and comprehensive email processing. By leveraging python-emails, developers can efficiently automate communication processes and focus on delivering robust applications, making it an excellent choice for enhancing any project's email functionality.

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.

How to 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',
               content_disposition='inline')W

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.

How to Send Email Messages using Templates via Python API?

from emails.template import JinjaTemplate as T

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

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'})

 English