Skip to main content

Django Multi Mail Backend

If you use or like the project, click Star and Watch to generate metrics and i evaluate project continuity.

Install:

pip install django-multi-mail-backend

Configuration

  1. Usage with multi backend

    1. In your settings.py:

      EMAIL_BACKEND = 'django_multi_mail_backend.backend.MultiServerBackend'
      
    2. set settings servers backend, in settings.py, ex:

      EMAIL_BACKENDS = {
          'smtp': {
              'BACKEND': 'django_multi_mail_backend.backend.MultiSMTPBackend',
              # settings for MultiSMTPBackend
          },
          'smtp2': {
              'BACKEND': 'django_multi_mail_backend.backend.MultiSMTPBackend',
              # settings for MultiSMTPBackend
          },
          'ses': {
              'BACKEND': 'django_multi_mail_backend.backend.MultiSESBackend',
              # settings for MultiSESBackend
          },
          'original_smtp': {
              'BACKEND': 'django.core.mail.backends.smtp.EmailBackend',
              # this use original django smtp class and configurations
          },
          'console': {
              'BACKEND': 'django.core.mail.backends.console.EmailBackend',
          }
      }
      
  2. Multi SMTP Server:

    1. In your settings.py:

      EMAIL_BACKEND = 'django_multi_mail_backend.backend.MultiSMTPBackend'
      
    2. set settings for MultiSMTPBackend in settings.py:

      # MultiSMTPBackend use django `django.core.mail.backends.smtp.EmailBackend` in the background
      EMAIL_BACKENDS = {
          'default': {
              # see all configuration here: https://docs.djangoproject.com/en/4.1/topics/email/#smtp-backend
              'HOST': 'mailhog',
              'PORT': 1025,
              'HOST_USER': None,
              'HOST_PASS': None,
              'USE_TLS': None,
              'USE_SSL': None,
              'TIMEOUT': None,
              'SSL_KEYFILE': None,
              'SSL_CERTFILE': None,
              'DEFAULT_FROM_EMAIL': "test@teste.com",
          },
          'example1': {
              # copy above settings
          }
      }
      
  3. Multi SES Server:

    1. In your settings.py:

      EMAIL_BACKEND = 'django_multi_mail_backend.backend.MultiSESBackend'
      
    2. set settings for MultiSESBackend in settings.py:

      # MultiSESBackend use django `django_ses.SESBackend` in the background
      # see all configuration here: https://github.com/django-ses/django-ses
      # removed `AWS_` in front of the keys
      EMAIL_BACKENDS = {
          'default': {
              'ACCESS_KEY': 'mailhog',
              'SECRET_KEY': 1025,
              'SESSION_TOKEN': None,
              'SES_REGION_NAME': None,
              'SES_REGION_ENDPOINT_URL': None,
              'SES_AUTO_THROTTLE': None,
              'SES_CONFIG': None,
              'DKIM_DOMAIN': None,
              'DKIM_PRIVATE_KEY': None,
              'DKIM_SELECTOR': None,
              'DKIM_HEADERS': None,
              'SES_SOURCE_ARN': None,
              'SES_FROM_ARN': None,
              'SES_RETURN_PATH_ARN': None,
          },
          'example1': {
              # copy above settings
          }
      }
      

Usage

Don't use default django methods direct, because this method not accept custom parameters, instead use the options below

  1. With send_mail

        from django_multi_mail_backend import send_mail, send_mass_mail
        ...
    
        send_mail(..., use_use_backend='smtp')
        send_mass_mail(..., use_backend='ses')
    

    or

        from django.core.mail import send_mail, send_mass_mail, get_connection
        ...
    
        with get_connection(use_backend='console') as connection:
            send_mail(..., connection=connection)
            send_mass_mail(..., connection=connection)
    
  2. With EmailMessage

    from django_multi_mail_backend import EmailMessage, EmailMultiAlternatives
    ...
    
    EmailMessage(..., use_backend='smtp2').send()
    EmailMultiAlternatives(..., use_backend='original_smtp').send()
    

    or

    from django.core.mail import EmailMessage, EmailMultiAlternatives, get_connection
    ...
    
    with get_connection(use_backend='smtp') as connection:
        EmailMessage(..., connection=connection).send()
        EmailMultiAlternatives(..., connection=connection).send()
    
  3. With send_messages

    from django_multi_mail_backend import EmailMessage, EmailMultiAlternatives, get_connection
    ...
    
    with get_connection(use_backend='smtp') as connection:
        connection.send_messages([EmailMessage(...), EmailMultiAlternatives(...)])
    

    or

    from django.core.mail import EmailMessage, EmailMultiAlternatives, get_connection
    ...
    
    with get_connection(use_backend='smtp') as connection:
        connection.send_messages([EmailMessage(...), EmailMultiAlternatives(...)])
    

Metadata

Release files for django-multi-mail-backend 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-multi-mail-backend 1.0.1
File Size Uploaded Provenance Actions
django-multi-mail-backend-1.0.1.tar.gz 7.2 kB Without provenance Details for django-multi-mail-backend-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-multi-mail-backend 1.0.1
File Interpreter ABI Platform Actions
django_multi_mail_backend-1.0.1-py3-none-any.whl Python 3 none any Details for django_multi_mail_backend-1.0.1-py3-none-any.whl

Total release size: 15.1 kB

Release files / django-multi-mail-backend-1.0.1.tar.gz

Download URL django-multi-mail-backend-1.0.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2ca6ee6594eb79e2956003ca1537ddfc147c0165560bca9238dd4b816d06b436
BLAKE2b-256 checksum
How to use checksums
15bd102ee05c2ca8edd0ad2a5a88108ad25b8b5ba010c1fe529f779031dca876
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / django_multi_mail_backend-1.0.1-py3-none-any.whl

Download URL django_multi_mail_backend-1.0.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
322832aebae84c71ad982b4361e4b805394fc7eeb467cd742418390a591e68b0
BLAKE2b-256 checksum
How to use checksums
b5417cc5c0b0e3d82ae84e54675bed70255151bd481c757ed197962c48a981af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Security for django-multi-mail-backend 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page