Cement core mail module.

class cement.core.mail.MailHandler(**kw)[source]

Bases: MailInterface, Handler

Mail handler implementation.


This handler supports the following configuration settings:

  • to - Default to addresses (list, or comma separated depending on the ConfigHandler in use)

  • from_addr - Default from_addr address

  • cc - Default cc addresses (list, or comma separated depending on the ConfigHandler in use)

  • bcc - Default bcc addresses (list, or comma separated depending on the ConfigHandler in use)

  • subject - Default subject

  • subject_prefix - Additional string to prepend to the subject

class Meta[source]

Bases: object

Handler meta-data (can be passed as keyword arguments to the parent class).

config_defaults = {'bcc': [], 'cc': [], 'from_addr': 'noreply@example.com', 'subject': 'Default Subject Line', 'subject_prefix': '', 'to': []}

Configuration default values


Called during application initialization and must setup the handler object making it ready for the framework or the application to make further calls to it.


app (instance) – The application object.

class cement.core.mail.MailInterface(**kw)[source]

Bases: Interface

This class defines the Mail Interface. Handlers that implement this interface must provide the methods and attributes defined below. In general, most implementations should sub-class from the provided MailHandler base class as a starting point.

class Meta[source]

Bases: object

Handler meta-data.

interface = 'mail'

The label identifier of the interface.

abstract send(body, **kwargs)[source]

Send a mail message. Keyword arguments override configuration defaults (cc, bcc, etc).


body (str) – The message body to send

Keyword Arguments:
  • to (list) – List of recipients (generally email addresses)

  • from_addr (str) – Address (generally email) of the sender

  • cc (list) – List of CC Recipients

  • bcc (list) – List of BCC Recipients

  • subject (str) – Message subject line


True if message was sent successfully, False otherwise

Return type:



# Using all configuration defaults
app.mail.send('This is my message body')

# Overriding configuration defaults
app.mail.send('My message body'
    cc=['jane@example.com', 'rita@example.com'],
    subject='This is my subject',