Introduction
mailables is a developer-centric utility for sending asynchronous mails.
Requirements
Python 3.7+
Installation
$ pip install mailables
Usage
from mailables import Mailer, EmailMessage
message = EmailMessage(
to='User Name <user@example.com>',
from_address='sender@example.com',
subject='Hey',
text_body='This is sent using mailables!',
html_body='<b>This is sent using mailables!</b>'
)
mailer = Mailer('smtp://localhost:25')
await mailer.send(message)
Dependencies
Mailables does not have any hard dependencies, but the following are optional:
aiofiles- required byFileTransport.aiosmtpdlib- required bySMTPTransport.
You can install all of these with pip install mailables[full].
Configuration
In order to send email you need to configure transport and mailer.
Mailer is a class with which you would work all time. Think it is a public interface to mailables.
And transport is a concrete adapter which does actual sending.
from mailables import Mailer
mailer = Mailer('smtp://localhost:25')
When you need to fine-grained control on the transport configuration you may pass the transport instance instead of URL string:
from mailables import Mailer, SMTPTransport
mailer = Mailer(SMTPTransport(host='localhost', port=25))
This approach gives you full control on transport construction.
Note, that you are not limited to one mailer only, your application may have multiple mailers with different transports/settings.
Mail message
The mail message is represented by EmailMessage class.
from mailables import EmailMessage
message = EmailMessage(
to=['root@localhost', 'admin@localhost'],
from_address='user@localhost',
subject='This is a test email',
text_body='And this is a body',
html_body='And HTML body <b>supported</b> as well',
)
Attaching files
from mailables import EmailMessage, Attachment
message = EmailMessage(
attachments=[
Attachment(contents='CONTENTS', file_name='file.txt')
]
)
# or alternatively using `attach` method:
message.attach(contents='CONTENTS', file_name='file.txt')
# or you can add attachment instance using `add_attachment` method:
message.add_attachment(Attachment('contents'))
Transports
Here is the list of included transports
SMTPTransport
Sends messages using SMTP protocol.
from mailables import SMTPTransport
transport = SMTPTransport(host='localhost', port=25, use_ssl=True)
FileTransport
File transport does not send email to anywhere. It dumps messages into mailbox directory in *.eml format.
from mailables import FileTransport
transport = FileTransport(directory='/tmp/mailbox')
InMemoryTransport
Stores sent emails in a local variable.
from mailables import InMemoryTransport, EmailMessage
storage = []
transport = InMemoryTransport(storage=storage)
# example:
transport.send(EmailMessage(subject='Hey', to='root@localhost'))
assert len(storage) == 1
NullTransport
This transport does not send anything at all. Use it when you want to completely silence the mailer.
from mailables import NullTransport
transport = NullTransport()
Building custom transports
Extend mailables.transport.BaseTransport class and
implement async def send(self, message: EmailMessage) method:
For example, we will create a simple transport class for writing mails to a stdout:
from mailables import BaseTransport, EmailMessage, Mailer
class ConsoleTransport(BaseTransport):
async def send(self, message: EmailMessage):
print(str(message))
mailer = Mailer(ConsoleTransport())
Metadata
Release files for mailables 0.0.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 | Provenance | Actions |
|---|---|---|---|---|
| mailables-0.0.2.tar.gz | 10.0 kB | Without provenance | Details for mailables-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mailables-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for mailables-0.0.2-py3-none-any.whl |
Total release size: 19.5 kB
Release files / mailables-0.0.2.tar.gz
| Download URL | mailables-0.0.2.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a56314f16bc81dc17222c590af4daaf20ead924f1ab146f3ffa008f16d41659f
|
|
BLAKE2b-256 checksum How to use checksums |
65d557a1d21b1ec6a723ee06ba657892cd2a7c778e27108f066ae25e10506476
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.4 Linux/5.3.11-arch1-1
|
Release files / mailables-0.0.2-py3-none-any.whl
| Download URL | mailables-0.0.2-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d0fd28200167abdc8a74ab14ab4f2d34ef826e0deb7b783de37924f91b3339a
|
|
BLAKE2b-256 checksum How to use checksums |
58446e1941ffbca464c284e8aee1d72d1f1ab4fe7c76836b2e2d89ea91c8081f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.4 Linux/5.3.11-arch1-1
|
Security for mailables 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.