cement.ext.ext_smtp

Cement smtp extension module.

class cement.ext.ext_smtp.SMTPMailHandler(**kw)[source]

Bases: MailHandler

This class implements the IMail interface, and is based on the smtplib standard library.

class Meta[source]

Bases: object

Handler meta-data.

config_defaults = {'auth': False, 'bcc': [], 'cc': [], 'files': None, 'from_addr': 'noreply@localhost', 'host': 'localhost', 'password': None, 'port': '25', 'ssl': False, 'subject': None, 'subject_prefix': None, 'timeout': 30, 'tls': False, 'to': [], 'username': None}

Configuration default values

label = 'smtp'

Unique identifier for this handler

send(body, **kw)[source]

Send an email message via SMTP. Keyword arguments override configuration defaults (cc, bcc, etc).

Parameters:

body (tuple) – The message body to send. Tuple is treated as: (<text>, <html>). If a single string is passed it will be converted to (<text>). At minimum, a text version is required.

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

  • subject_prefix (str) – Prefix for message subject line (useful to override if you want to remove/change the default prefix).

  • files (list) – List of file paths to attach to the message. Can be [ '/path/to/file.ext', ... ] or alternative filename can be defined by passing a list of tuples in the form of [ ('alt-name.ext', '/path/to/file.ext'), ...]

Returns:

True if message is 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'
    from_addr='me@example.com',
    to=['john@example.com'],
    cc=['jane@example.com', 'rita@example.com'],
    subject='This is my subject',
    )