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
| Attribute | Type | Description |
|---|---|---|
| default | [BaseEmailBackend](../backends/base/baseemailbackend.md?sid=django_core_mail_backends_base_baseemailbackend) | The default mailer connection instance retrieved using the DEFAULT_MAILER_ALIAS. |
| settings | dict | A dictionary containing the mailer configurations defined in the Django MAILERS setting. |
| _is_configured | boolean | True 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
| Name | Type | Description |
|---|---|---|
| alias | string | The identifier for the desired mailer configuration. |
| default | any = None | The value to return if the specified alias is not found in settings. |
Returns
| Type | Description |
|---|---|
| `BaseEmailBackend | Any` |
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
| Type | Description |
|---|---|
[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
| Type | Description |
|---|---|
dict | A 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
| Name | Type | Description |
|---|---|---|
| alias | string | The configuration key used to look up backend settings and options. |
| _deprecated_kwargs | dict = None | Internal parameter used to pass legacy connection arguments during the transition to the MAILERS setting. |
Returns
| Type | Description |
|---|---|
[BaseEmailBackend](../backends/base/baseemailbackend.md?sid=django_core_mail_backends_base_baseemailbackend) | An initialized email backend instance ready to send messages. |