Skip to content

Support Django 6.1 MAILERS configuration #472

Description

@medmunds

Django 6.1 will allow configuring multiple email backends via a new MAILERS dict setting with separate OPTIONS for each configuration. It also deprecates the current EMAIL_BACKEND setting.

Anymail's backends already allow configuration by keyword arguments, so already support MAILERS and OPTIONS. These settings should work just fine with the current django-anymail 15.0 (or earlier) and Django 6.1:

MAILERS = {
    "default": {
        "BACKEND": "anymail.backends.amazon_ses.EmailBackend",
        "OPTIONS": {
            "client_params": {"region_name": "us-west-2"},
            "configuration_set_name": "django-transactional",
        },
    },
    "marketing": {
        "BACKEND": "anymail.backends.postmark.EmailBackend",
        "OPTIONS": {
            "server_token": "...",
            "send_defaults": {
                "esp_extra": {"MessageStream": "broadcast"},
            },
        },
    },
    "sandbox": {
        "BACKEND": "anymail.backends.mailtrap.EmailBackend",
        "OPTIONS": {
            "api_token": "...",
            "sandbox_id": 12345,
        },
    },
}

# And no need to define ANYMAIL settings for sending.
# (You might still need ANYMAIL for, e.g., webhook validation keys.)

But we need to:

  • Update Anymail's documentation to show configuration via MAILERS (and explain that MAILERS OPTIONS take precedence over the corresponding ANYMAIL settings when both are defined)
  • Update Anymail's tests to avoid use of deprecated EMAIL_BACKEND on Django 6.1 or later
  • Consider adding some ESP-specific OPTIONS that are currently available only as global send defaults with esp_extra, to simplify configuration (e.g., Postmark's MessageStream like shown above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions