asphalt.mailer.api
- exception asphalt.mailer.api.DeliveryError(error, message=None)
Raised when there’s an error with mail delivery.
- Variables
error – the error message
message – the email message related to the failure, if any
- class asphalt.mailer.api.Mailer(message_defaults=None)
This is the abstract base class for all mailers.
- Parameters
message_defaults – default values for omitted keyword arguments of
create_message()
- classmethod add_attachment(msg, content, filename, mimetype=None)
Add binary data as an attachment to an
EmailMessage
.The default value for the
mimetype
argument is guessed from the file name. If guessing fails,application/octet-stream
is used.
- classmethod coroutine add_file_attachment(msg, path, filename=None, mimetype=None)
Read the contents of a file and add them as an attachment to the given message.
Reads the file contents and then passes the result as
content
toadd_attachment()
along with the rest of the arguments.
- create_and_deliver(**kwargs)
Build a new email message and deliver it.
This is a shortcut to calling
create_message()
and then passing the result todeliver()
.- Parameters
kwargs – keyword arguments passed to
create_message()
- create_message(*, subject=None, sender=None, to=None, cc=None, bcc=None, charset=None, plain_body=None, html_body=None)
Create an
EmailMessage
using to be sent later usingdeliver()
.- Parameters
subject (str | None) – subject line for the message
sender (str | Address | None) – sender address displayed in the message (the From: header)
to (AddressListType | None) – primary recipient(s) (displayed in the message)
cc (AddressListType | None) – secondary recipient(s) (displayed in the message)
bcc (AddressListType | None) – secondary recipient(s) (not displayed in the message)
charset (str | None) – character encoding of the message
plain_body (str | None) – plaintext body
html_body (str | None) – HTML body
- Return type
EmailMessage
- coroutine deliver(self, messages)
Deliver the given message(s).
- Parameters
messages (EmailMessage | Iterable[EmailMessage]) – the message or iterable of messages to deliver
- Return type
None