Sending Email Messages

Cement defines a mail interface called IMail, as well as the default DummyMailHandler that implements the interface.

Please note that there are other handlers that implement the IMail interface. The documentation below only references usage based on the interface and not the full capabilities of the implementation.

The following mail handlers are included and maintained with Cement:

Please reference the IMail interface documentation for writing your own mail handler.

Example Usage

from import CementApp

class MyApp(CementApp):
    class Meta:
        label = 'myapp'

with MyApp() as app:

    # send an email message
    app.mail.send('This is my message',
        subject='This is my subject',
        cc=['', ''],

Note that the default mail handler simply prints messages to the screen, and does not actually send anything. You can override this pretty easily without changing any code by using the built-in SMTPMailHandler. Simply modify the application configuration to something like:


mail_handler = smtp

ssl = 1
tls = 1
auth = 1
username = john.doe
password = oober_secure_password