Jump to >


E-mail message composition and sending.

class EmailMessage(subject='', text_body='', html_body='', from_email=None, to=None, cc=None, bcc=None, sender=None, in_reply_to=None, headers=None, auto_generated=False, prevent_auto_responses=False, from_spoofing=None, enable_smart_spoofing=None)[source]

An EmailMesssage subclass with improved header and message ID support.

This class knows about several headers (standard and variations), including Sender/X-Sender, In-Reply-To/References`, and Reply-To.

The generated Message-ID header from the e-mail can be accessed via the message_id attribute after the e-mail has been sent.

In order to prevent issues when sending on behalf of users whose e-mail domains are controlled by DMARC, callers can specify from_spoofing (or set settings.DJBLETS_EMAIL_FROM_SPOOFING). When set, the e-mail address used for the From header will only be used if there aren’t any DMARC rules that may prevent the e-mail from being sent/received.


Releases prior to Djblets 1.0.10 required using enable_smart_spoofing or settings.EMAIL_ENABLE_SMART_SPOOFING, which didn’t allow From spoofing to be completely disabled.)

In the event that a DMARC rule would prevent sending on behalf of that user, the sender address will be used instead, with the full name appearing as the value in from_email with “via <Service Name>” tacked onto it.

Callers wishing to use this should also set settings.EMAIL_DEFAULT_SENDER_SERVICE_NAME to the desired service name. Otherwise, the domain on the sender e-mail will be used instead.

This class also supports repeated headers.

Changed in version 1.0.10: Added the from_spoofing parameter and settings.DJBLETS_EMAIL_FROM_SPOOFING to replace enable_smart_spoofing and settings.EMAIL_ENABLE_SMART_SPOOFING.

FROM_SPOOFING_ALWAYS = 'always'[source]

Always spoof the From address for a user.

FROM_SPOOFING_SMART = 'smart'[source]

Only spoof the From address for a user if allowed by DMARC rules.

FROM_SPOOFING_NEVER = 'never'[source]

Never spoof the From address for a user.


Construct an outgoing message for the e-mail.

This will construct a message based on the data provided to the constructor. This represents the e-mail that will later be sent using send().

After calling this method, the message’s ID will be stored in the message_id attribute for later reference.

This does not need to be called manually. It’s called by send().


The resulting message.

Return type



Return a list of all recipients of the e-mail.


A list of all recipients included on the To, CC, and BCC lists.

Return type