__init__(recipient_email_list: Union[list, str] = None, context_data: dict = None)
Takes a list of recipient email addresses or just a single email address as a string and optionally some context data.
recipient_email_list might be none, because you could set the variable statically in the class definition.
get_context_data()
Similar to django CBVs known method, you can extend here the context_data provided in the __init__().
get_subject()
This method combines the constants SUBJECT_PREFIX and SUBJECT_DELIMITER with the variable subject. Can be overwritten, if required.
get_from_email()
Returns the email address the mail should be sent from. Will take the django settings variable DEFAULT_FROM_EMAIL
if the constant FROM_EMAIL in the class is not set.
get_recipient_emails()
Returns the content of class variable recipient_email_list, which holds the recipients of the email. Can
automatically be filled by passing the kwarg recipient_email_list in the constructor. Override it to resolve the
recipients dynamically, returning a list even for a single recipient. Mind that an override takes precedence over
anything passed to the constructor, so a service class used by a BaseEmailServiceFactory will ignore the
address the factory hands it. The method is called more than once per
email (once for validation, once for building the mail object), so cache the result yourself if resolving is
expensive or if the underlying data can change mid-send.
get_reply_to_email()
Returns the content of constant REPLY_TO_ADDRESS. If this constant is not set, there will be no “reply-to” data in
the email.
get_cc_to_email()
Returns the content of class variable cc_email_list_. Any email address returned by this method will be used in
the “CC” field of the generated email. This variable can be set anywhere within the class
(preferably in the __init__ method) or this method can be overwritten for custom behaviour.
get_bcc_to_email()
Returns the content of class variable bcc_email_list_. Any email address returned by this method will be used in
the “CC” field of the generated email. This variable can be set anywhere within the class
(preferably in the __init__ method) or this method can be overwritten for custom behaviour.
get_translation()
Returns the language from the django settings variable LANGUAGE_CODE, which is used to activate that langauge
during email rendering. Can be overwritten to return any language code django accepts. When returning a falsy value
language activation is skipped.
get_attachments()
This method returns a list of paths to a locally-stored file. Can automatically be filled by passing the kwarg
attachment_list in the constructor. Each file of the given list will be attached to the newly created email.
has_errors()
If is_valid() is called with the keyword argument raise_exception=False, the configuration errors are not raised
but stored internally. This method checks if any errors occurred. If you need the explicit errors, you can fetch them
via the errors property.
process()
Executes the actual sending. Not recommended to change. Returns True if the email was sent. Errors occurring while
sending are logged and then raised, unless the used connection was created with fail_silently=True. The keyword
argument raise_exception only affects configuration errors, not sending errors.
get_connection()
Returns the connection the email is sent with. Returns None by default, which lets django create one. Override it
to provide your own, for example to make a factory batch fail silently.
_should_fail_silently(msg)
Decides whether an error occurring while sending is swallowed or propagated to the caller. Defaults to the
fail_silently flag of the connection used for sending. See “Error handling” in the configuration chapter.