{"id":6600,"library":"django-sendgrid-v5","title":"Django SendGrid v5 Backend","description":"An implementation of Django's EmailBackend compatible with sendgrid-python v5+. It allows Django applications to send emails via SendGrid's API, leveraging SendGrid's full feature set including personalizations, attachments, and tracking. The current version is 1.3.1, and it typically releases updates every few months.","status":"active","version":"1.3.1","language":"en","source_language":"en","source_url":"https://github.com/sklarsa/django-sendgrid-v5","tags":["django","email","sendgrid","backend"],"install":[{"cmd":"pip install django-sendgrid-v5","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for Django EmailBackend integration. Currently supports Django >= 3.2, < 5.3.","package":"Django","optional":false},{"reason":"Core SendGrid API client. Requires sendgrid >= 5.0.0.","package":"sendgrid","optional":false}],"imports":[{"note":"The top-level package for the backend is `sendgrid_backend`, not `django_sendgrid_v5`.","wrong":"from django_sendgrid_v5 import SendgridBackend","symbol":"SendgridBackend","correct":"from sendgrid_backend import SendgridBackend"},{"note":"Introduced in v1.3.0 for easier webhook development.","symbol":"verify_sendgrid_webhook_signature","correct":"from sendgrid_backend.utils import verify_sendgrid_webhook_signature"}],"quickstart":{"code":"import os\nfrom django.core.mail import send_mail, EmailMessage\nfrom django.conf import settings\n\n# --- Minimal Django settings configuration for demonstration ---\n# In a real Django project, these would be in your settings.py\n# and Django's settings would already be configured.\nif not settings.configured:\n    settings.configure(\n        EMAIL_BACKEND='sendgrid_backend.SendgridBackend',\n        SENDGRID_API_KEY=os.environ.get('SENDGRID_API_KEY', 'DUMMY_SENDGRID_API_KEY'),\n        # Optional: Set sandbox mode for testing without sending real emails\n        # SENDGRID_SANDBOX_MODE=True,\n        DEBUG=True # Required for settings.configure\n    )\n\nprint(f\"Using SendGrid API Key: {settings.SENDGRID_API_KEY[:5]}... (first 5 chars)\")\n\n# --- Sending a basic email ---\ntry:\n    send_mail(\n        'Hello from Django SendGrid!',\n        'This is a test email sent via SendGrid.',\n        'from@example.com', # Must be a verified sender in SendGrid\n        ['to@example.com'],\n        fail_silently=False,\n    )\n    print(\"Basic email sent successfully (or attempted if in sandbox).\")\nexcept Exception as e:\n    print(f\"Error sending basic email: {e}\")\n\n# --- Sending an email with more options using EmailMessage ---\ntry:\n    email = EmailMessage(\n        'Advanced Django SendGrid Email',\n        'This email uses EmailMessage for more control.',\n        'from@example.com',\n        ['to@example.com'],\n        reply_to=['reply@example.com'],\n        headers={'X-Custom-Header': 'My-Value'},\n    )\n    # Example of adding a personalization (requires sendgrid.Personalization object or dict)\n    # from sendgrid.helpers.mail import Personalization, Email\n    # p = Personalization()\n    # p.add_to(Email('another_recipient@example.com'))\n    # email.personalizations = [p]\n\n    # Example of using a SendGrid Dynamic Template\n    # email.template_id = 'd-xxxxxxxxxxxxxxxxxxxxxxx'\n    # email.dynamic_template_data = {'name': 'User', 'message': 'Welcome!'}\n\n    email.send(fail_silently=False)\n    print(\"Advanced email sent successfully (or attempted if in sandbox).\")\nexcept Exception as e:\n    print(f\"Error sending advanced email: {e}\")","lang":"python","description":"Configure `EMAIL_BACKEND` and `SENDGRID_API_KEY` in your Django `settings.py`. Then use Django's standard `send_mail` or `EmailMessage` functions to send emails. Ensure `SENDGRID_API_KEY` is set as an environment variable or directly in settings. `SENDGRID_SANDBOX_MODE = True` can be used for testing without consuming SendGrid credits."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.6 or newer. (Currently supports Python >=3.8)","message":"Python 2 support was dropped entirely in version 1.0.0. Projects using older Python versions must upgrade Python before upgrading to `django-sendgrid-v5` v1.0.0 or later.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure your project runs on supported Python and Django versions (e.g., Python >=3.8, Django >=3.2, <5.3). Review the project's pyproject.toml for exact version constraints.","message":"Version 1.3.0 and 1.3.1 dropped support for several older Python and Django versions. Specifically, v1.3.1 dropped support for Django 5.0, now requiring Django 5.2 or later for Django 5.x series.","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"In your Django `settings.py`, ensure `EMAIL_BACKEND = 'sendgrid_backend.SendgridBackend'` is set.","message":"The `EMAIL_BACKEND` setting in Django must be correctly configured to point to `sendgrid_backend.SendgridBackend` for the library to be used.","severity":"gotcha","affected_versions":"*"},{"fix":"Set `SENDGRID_API_KEY = os.environ.get('SENDGRID_API_KEY', 'your_fallback_key')` in your `settings.py`.","message":"The `SENDGRID_API_KEY` must be provided in your Django settings, typically via an environment variable, for authentication with SendGrid.","severity":"gotcha","affected_versions":"*"},{"fix":"Verify the sender email address(es) in your SendGrid dashboard.","message":"The `from_email` specified in `send_mail` or `EmailMessage` must be a sender email address verified in your SendGrid account, or emails will fail.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}