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 = u'This is a plain text message'
mailer.send_plain(
u'sender@example.com',
[u'recipient@example.com'],
u'hi',
message
)
Sending an HTML message:
message = u'<html><body>Look! HTML!</body></html>'
mailer.send_html(
u'sender@example.com',
[u'recipient@example.com'],
u'hi',
message
)
Adding attachments:
message = u'index.rst is attached to this message'
mailer.send_plain(
u'sender@example.com',
[u'recipient@example.com'],
u'hi',
message,
attachments=['index.rst']
)
Metadata
Release files for mailtools 2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mailtools-2.tar.gz | 17.9 kB | Details |
Release files / mailtools-2.tar.gz
| Download URL | mailtools-2.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c980e4a95998f2171ca9e7dd5356e0a8145b1c8871a9d36b7af087932f862bd2
|
|
BLAKE2b-256 checksum How to use checksums |
00bbc77bffa55930821e4d62e2d8ee270205a2ae7d3935b3a757c1d1d8d44314
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |