emailtools.cbe.base

This document provides API reference material for the classes and mixins found in emailtools.

BaseEmail

class emailtools.cbe.base.BaseEmail

This is the base class for all class based emails. While not usable on its own, it establishes the base api for email sending.

email_message_class

The class that will be used to construct the email message.

get_email_message_class()

Returns the email message class.

get_email_message_kwargs()

Constructs and returns the kwargs that will be used to instantiate the email message.

get_email_message()

Constructs and returns the instantiated email message.

get_send_kwargs(**kwargs)

Construct and returns the kwargs that will be passed to the send method of the instantiated email message.

send()

Constructs and sends the email message.

as_callable()

Returns the email callable that can be used to send the email message, or construct and return the unsent email message.

BasicEmail

class emailtools.cbe.base.BasicEmail

This class is the simplest implementation for class-based emails, and can be thought of as a loose wrapper around django.core.email.EmailMessage. The class provides properties and methods for declaring or building each of the arguments used to instantiate and send an EmailMessage.

email_message_class
  • default: django.core.email.EmailMessage
``subject``

Static property to be used as the subject attribute for the email message.

``to``

Static property to be used as the to address for the email message.

``cc``

Static property to be used as the cc attribute for the email message.

``bcc``

Static property to be used as the bcc attribute for the email message.

``from_email``

Static property to be used as the from_email attribute for the email message.

``body``

Static property to be used as the body attribute for the email message.

``connection``

Static property to be used as the connection to be used for sending the email message.

``attachments``

Static property to be used for the attachments of the email message.

``headers``

Static property to be used for the headers of the email message.

``fail_silently``

Passed to the send method of the email message, to determine whether exceptions raised while sending should be squashed.

``get_to``

Returns the list of email addresses the email addresses should be sent to.

``get_cc``

Returns the list of email addresses the email addresses should be cc’d.

``get_bcc``

Returns the list of email addresses the email addresses should be bcc’d.

``get_from_email``

Returns the email address the email addresses will be from.

``get_body``

Returns the message body for the email message.

``get_connection``

Returns the email connection to be used for sending the email message.

``get_headers``

Returns any headers to be added to the email message.

HTMLEmail

class emailtools.cbe.base.HTMLEmail

This class leverages the django template engine to attach an html message to the email message.

email_message_class
  • default: django.core.email.EmailMessage
template_name

Path to the template that should be used for rendering the body of the message.

get_context_data(**kwargs)

Constructs and returns the context to be used for template rendering.

MarkdownEmail

class emailtools.cbe.base.MarkdownEmail

Similar to HTMLEmail, this class uses the django template engine for rendering an html email message. It however expects a template written in markdown, which is then inserted into the body of a base html template.

layout_template

Declares what template should be used as the base layout for this email. This template should expect a context variable content which will contain the rendered markdown of the message.

template_name

Path to the template that should be used for rendering the body of the message. This template is rendered as markdown and then inserted into the template returned by get_layout_template().

get_context_data(**kwargs)

Constructs and returns the context to be used for template rendering.

get_layout_template()

Returns the template that should be used for rending the base html layout of the message. If layout_template is not set on the class, this method returns the value found in settings.EMAIL_LAYOUT. This template will be rendered with the context returned by get_layout_context_data(), which by default contains one value content which is the rendered markdown content.

get_layout_context_data(**kwargs)

Constructs and renders the context data for the base layout template. By default, this returns a context with a single value content which contains the rendered markdown content from the markdown template.