Skip to main content

MailersHandler

This class manages the lifecycle and configuration of mailer connections based on defined settings. It provides a dictionary-like interface to access mailer instances by alias, supporting iteration, membership testing, and default connection retrieval. The handler dynamically imports and initializes backend classes using specified options and configurations.

Attributes

AttributeTypeDescription
default[BaseEmailBackend](../backends/base/baseemailbackend.md?sid=django_core_mail_backends_base_baseemailbackend)The default mailer connection instance retrieved using the DEFAULT_MAILER_ALIAS.
settingsdictA dictionary containing the mailer configurations defined in the Django MAILERS setting.
_is_configuredbooleanTrue if settings.py has opted into MAILERS support.

Methods


get()

@classmethod
def get(
alias: string,
default: any = None
) - > BaseEmailBackend | Any

Attempts to retrieve a mailer connection, returning a default value if the alias does not exist.

Parameters

NameTypeDescription
aliasstringThe identifier for the desired mailer configuration.
defaultany = NoneThe value to return if the specified alias is not found in settings.

Returns

TypeDescription
`BaseEmailBackendAny`

default()

@classmethod
def default() - > [BaseEmailBackend](../backends/base/baseemailbackend.md?sid=django_core_mail_backends_base_baseemailbackend)

Accesses the connection instance for the default mailer alias.

Returns

TypeDescription
[BaseEmailBackend](../backends/base/baseemailbackend.md?sid=django_core_mail_backends_base_baseemailbackend)The mailer backend instance configured as the system default.

settings()

@classmethod
def settings() - > dict

Retrieves the raw MAILERS configuration dictionary from the project settings.

Returns

TypeDescription
dictA dictionary containing mailer aliases and their respective backend configurations.

create_connection()

@classmethod
def create_connection(
alias: string,
_deprecated_kwargs: dict = None
) - > [BaseEmailBackend](../backends/base/baseemailbackend.md?sid=django_core_mail_backends_base_baseemailbackend)

Instantiates a mailer backend based on the configuration associated with the given alias.

Parameters

NameTypeDescription
aliasstringThe configuration key used to look up backend settings and options.
_deprecated_kwargsdict = NoneInternal parameter used to pass legacy connection arguments during the transition to the MAILERS setting.

Returns

TypeDescription
[BaseEmailBackend](../backends/base/baseemailbackend.md?sid=django_core_mail_backends_base_baseemailbackend)An initialized email backend instance ready to send messages.