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)¶
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_idattribute 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
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
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
senderaddress will be used instead, with the full name appearing as the value in
from_emailwith “via <Service Name>” tacked onto it.
Callers wishing to use this should also set
settings.EMAIL_DEFAULT_SENDER_SERVICE_NAMEto 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_ALWAYS = 'always'¶
Always spoof the From address for a user.
- FROM_SPOOFING_SMART = 'smart'¶
Only spoof the From address for a user if allowed by DMARC rules.
- FROM_SPOOFING_NEVER = 'never'¶
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
After calling this method, the message’s ID will be stored in the
message_idattribute for later reference.
This does not need to be called manually. It’s called by
The resulting message.
- Return type