Skip to main content

Mailtools

Writing a web application? Want to send some emails from it? Mailtools can help!

  • Simple API for sending plain text messages, HTML and messages with attachments.

  • ThreadedMailer sends emails in the background and returns control to your application immediately, even when talking to slow remote servers.

  • Temporary sending failures are automatically retried.

  • Running your application in test mode? The RedirectMessages wrapper routes emails to a test address and not to live email addresses.

Usage

Creating a simple SMTP mailer:

from mailtools import SMTPMailer
mailer = SMTPMailer('127.0.0.1')

This mailer will block until messages are sent and won’t retry failures. Use ThreadedMailer to fix this:

mailer = ThreadedMailer(SMTPMailer('127.0.0.1'))

A mailer with TLS/STARTTLS support:

mailer = SMTPMailer('127.0.0.1', 465, transport_args={'security': 'TLS'})
mailer = SMTPMailer('127.0.0.1', transport_args={'security': 'STARTTLS'})

Sending a plain text message:

message = 'This is a plain text message'
mailer.send_plain(
        'sender@example.com',
        ['recipient@example.com'],
        'hi',
        message
)

Sending an HTML message:

message = '<html><body>Look! HTML!</body></html>'
mailer.send_html(
        'sender@example.com',
        ['recipient@example.com'],
        'hi',
        message
)

Adding attachments:

message = 'index.rst is attached to this message'
mailer.send_plain(
        'sender@example.com',
        ['recipient@example.com'],
        'hi',
        message,
        attachments=['index.rst']
)

CHANGELOG

3.0.1 (released 2019-11-06)

  • Fixed PyPI package metadata

3.0.0 (released 2019-11-06)

  • Added Python 3 support

  • Dropped Python 2 support

Version 2.1

  • Added a ThreadedMailer.shutdown method (thanks to Andrew Nelis for an initial implementation and advice on the design of this feature)

Version 2

  • Added TLS/STARTTLS support (thanks to w31rd0 for the implementation of this)

Version 1

  • Initial release

Metadata

Release files for mailtools 3.0.1

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

Source distribution (sdist)

Source distribution for mailtools 3.0.1
File Size Uploaded
mailtools-3.0.1.tar.gz 16.4 kB Details

Built distribution (wheel)

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

Total release size: 30.2 kB

Release files / mailtools-3.0.1.tar.gz

Download URL mailtools-3.0.1.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
161594e195b53d737e2a6731254be9221ad413ad9a9d9eeb889659c7f851ca5e
BLAKE2b-256 checksum
How to use checksums
be09afc080f4f420f4ee925442a063ffd0a4ae6dc7c61a261adeefbccddd89b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.6.9

Release files / mailtools-3.0.1-py3-none-any.whl

Download URL mailtools-3.0.1-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcb8dc584c6f62c70b537305aa28c96ce02e4d6eb978578a1db08d2a998d1e70
BLAKE2b-256 checksum
How to use checksums
7d32584696ba39b65e3f6c82f8d344081bdddb7a7d81250372008771b9d47bda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.1

1 release file

2

1 release file

1

1 release file

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