cyclone.mail — Send e-mails with attachments

Support for sending e-mails with attachments to SMTP servers over plain text, SSL or TLS.

For more information, check out the e-mail demo.

class cyclone.mail.Message(from_addr, to_addrs, subject, message, mime='text/plain', charset='utf-8')[source]

Create new e-mail messages.

Example:

msg = mail.Message(
        from_addr="root@localhost",
        to_addrs=["user1", "user2", "user3"],
        subject="Test, 123",
        message="Hello thar!",
        mime="text/html")
attach(filename, mime=None, charset=None, content=None)[source]

Attach files to this message.

Example:

msg.attach("me.png", mime="image/png")

It also supports fake attachments:

msg.attach("fake.txt", mime="text/plain", content="gotcha")
add_header(key, value, **params)[source]

Adds custom headers to this message.

Example:

msg.add_header("X-MailTag", "foobar")
cyclone.mail.sendmail(mailconf, message)[source]

Takes a regular dictionary as mailconf, as follows.

Example:

mailconf = dict(
    host="smtp.gmail.com",  # required
    port=25,                # optional, default 25 or 587 for SSL/TLS
    username=foo,           # optional, no default
    password=bar,           # optional, no default
    tls=True,               # optional, default False
)

d = mail.sendmail(mailconf, msg)
d.addCallback(on_response)

Previous topic

cyclone.httpclient — Non-blocking HTTP client

Next topic

Integration with other services

This Page