cement.core.mail

Cement core mail module.

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

Bases: cement.core.mail.MailInterface, cement.core.handler.Handler

Mail handler implementation.

Configuration

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

_setup(app_obj)[source]

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.

Parameters:app (instance) – The application object.
class cement.core.mail.MailInterface(**kw)[source]

Bases: cement.core.interface.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.

send(body, **kwargs)[source]

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

Parameters:

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
Returns:

True if message was sent successfully, False otherwise

Return type:

bool

Example

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

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