Sendable emails

class emailpal.SendableEmail[source]

This abstract base class represents a template-based email that can be sent in HTML and plaintext formats.

When generating the email, the template is actually rendered twice: once as HTML, and again as plain text. As explained in “There are people who can’t read HTML email?”, this allows both formats to share most of their content, yet also deviate where necessary.

So, aside from the context your code provides, the following context variables are provided when rendering your template:

  • is_html_email is True if (and only if) the template is being used to render the email’s HTML representation.
  • is_plaintext_email is True if (and only if) the template is being used to render the email’s plaintext representation.

Note that when rendering the email as plaintext, HTML tags are automatically stripped from the generated content.

create_message(ctx: T, from_email=None, to=None, bcc=None, connection=None, attachments=None, headers=None, alternatives=None, cc=None, reply_to=None) → django.core.mail.message.EmailMessage[source]

Creates and returns a django.core.mail.EmailMessage which contains the plaintext and HTML versions of the email, using the context specified by ctx.

Aside from ctx, arguments to this method are the same as those for EmailMessage.

example_ctx

An example context with which the email can be rendered.

subject

The subject line of the email. This is processed by str.format() and passed the same context that is passed to templates when rendering the email, so you can include context variables via brace notation, e.g. "Hello {full_name}!".

template_name

The path to the template used to render the email, e.g. "my_app/my_email.html".