Skip to content

Replace django-sendgrid for mail sending #8754

Open

Description

@matthewelwell

django-sendgrid appears unsupported (https://ryanbalfanz.github.com/django-sendgrid/).

We should move to another more supported library for handling mail distribution through Sendgrid, e.g. django-anymail (although that also states that Sendgrid is untested).

Acceptance Criteria

Activity

  1. twinkalp10 commented on Oct 16, 2026

    @twinkalp10

    Small observation that might make this easier: settings/common.py already supports django.core.mail.backends.smtp.EmailBackend; sgbackend.SendGridBackend is only the default when SENDGRID_API_KEY is set. SendGrid supports plain SMTP, so you could drop django-sendgrid without adding anymail. Keep the backwards compatibility by mapping the existing key onto the SMTP path:

    SENDGRID_API_KEY = env("SENDGRID_API_KEY", default=None)
    
    EMAIL_BACKEND = env("EMAIL_BACKEND", default="django.core.mail.backends.smtp.EmailBackend")
    
    if EMAIL_BACKEND == "django.core.mail.backends.smtp.EmailBackend":
        if SENDGRID_API_KEY:
            EMAIL_HOST = "smtp.sendgrid.net"
            EMAIL_HOST_USER = "apikey"
            EMAIL_HOST_PASSWORD = SENDGRID_API_KEY
        else:
            EMAIL_HOST = env("EMAIL_HOST", default="localhost")
            EMAIL_HOST_USER = env("EMAIL_HOST_USER", default=None)
            EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD", default=None)
        EMAIL_PORT = env("EMAIL_PORT", default=587)
        EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", default=True)

    Existing deployments with only SENDGRID_API_KEY keep working, the dependency goes away, and there's one email code path to test instead of two.

    (Disclosure: I'm the founder of Reloop: https://github.com/reloop-labs/reloop, an open-source email API with SMTP support. Since self-hosters already use the SMTP path, it's one of the providers that works there with no changes. Happy to help test this if useful.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions