Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python-emails Documentation: Modern Email Handling in Python, Study Guides, Projects, Research of Advanced Computer Programming

Information about python-emails, a Python library for handling HTML emails. It includes features such as HTML-email message abstraction, DKIM signature, message loaders, and the ability to send emails directly or via Django email backend. The document also covers examples of creating and sending emails, transforming HTML bodies, and loading messages from various sources.

Typology: Study Guides, Projects, Research

2021/2022

Uploaded on 09/12/2022

ahalya
ahalya 🇺🇸

4.9

(16)

257 documents

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
python-emails Documentation
Release 0.5.1
Sergey Lavrinenko
Oct 08, 2018
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download Python-emails Documentation: Modern Email Handling in Python and more Study Guides, Projects, Research Advanced Computer Programming in PDF only on Docsity!

python-emails Documentation

Release 0.5.

Sergey Lavrinenko

Oct 08, 2018

ii

python-emails Documentation, Release 0.5.

Modern email handling in python.

m = emails.Message(html=T("

Build passed: {{ project_name }} <img src= ˓→'cid:icon.png'> ..."), text=T("Build passed: {{ project_name }} ..."), subject=T("Passed: {{ project_name }}#{{ build_id }}"), mail_from=("CI", "ci@mycompany.com")) m.attach(filename="icon.png", content_disposition="inline", data=open("icon.png", "rb ˓→")) response = m.send(render={"project_name": "user/project1", "build_id": 121}, to='somebody@mycompany.com', smtp={"host":"mx.mycompany.com", "port": 25})

if response.status_code not in [250, ]:

message is not sent, retry later

...

See the same code, without Emails.

Emails code is not much simpler than the same code in django, but it is still more elegant, can be used in django

environment and has html transformation methods (see HTML Transformer section).

Contents 1

CHAPTER 1

Features

  • HTML-email message abstraction
  • Method to transform html body:
    • css inlining (using peterbe’s premailer)
    • image inlining
  • DKIM signature
  • Message loaders
  • Send directly or via django email backend

python-emails Documentation, Release 0.5.

4 Chapter 1. Features

python-emails Documentation, Release 0.5.

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

6 Chapter 2. Examples

CHAPTER 3

Django

DjangoMessage helper sends via django configured email backend:

from emails.django import DjangoMessage as Message message = Message(...) message.send(mail_to=('John Brown', 'jbrown@gmail.com'), context={'name': 'John'})

CHAPTER 4

Flask

For flask integration take a look at flask-emails

python-emails Documentation, Release 0.5.

10 Chapter 4. Flask

python-emails Documentation, Release 0.5.

12 Chapter 5. HTML transformer

CHAPTER 6

Loaders

python-emails ships with couple of loaders.

Load message from url:

import emails.loader message = emails.loader.from_url(url="http://xxx.github.io/newsletter/2015-08-14/ ˓→index.html")

Load from zipfile or directory:

message = emails.loader.from_zipfile(open('design_pack.zip', 'rb')) message = emails.loader.from_directory('/home/user/design_pack')

Zipfile and directory loaders require at least one html file (with “html” extension).

Load message from .eml file (experimental):

message = emails.loader.from_rfc822(open('message.eml').read())

CHAPTER 7

Install

Install from pypi:

$ [sudo] pip install emails

Install on Ubuntu from PPA:

$ [sudo] add-apt-repository ppa:lavrme/python-emails-ppa $ [sudo] apt-get update $ [sudo] apt-get install python-emails

python-emails Documentation, Release 0.5.

16 Chapter 7. Install