Defer your emails using Twisted.
from txmail.smtp import Sender
subject = 'An Example of Life and Love and Emails'
body = 'Hey ya'
from_email = '[email protected]'
name = 'Tx Mail'
sender = Sender(
smtp_server,
username,
password,
port=587,
starttls=True,
from_name=name,
from_email=from_email
)
d = sender.send(['[email protected]', '[email protected]'], subject, body)
d.addCallback(_email_sent)
And yes, we support attachment(s).
attachments = ('pulpnonfiction.txt', 'lifeaftergod.md')
d = sender.send(
['[email protected]', '[email protected]'],
subject, body, attachments=attachments)
d.addCallback(_email_sent)
For more, take a look at the docs.