Immutable solution version
SendGrid with Django: SMTP backend settings that actually work
Complete solution
Wire Django's SMTP email backend to SendGrid: the six settings, the literal apikey username trap, and pulling the key from the environment instead of settings.py.
In settings.py (or your settings module):
EMAILBACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAILHOST = 'smtp.sendgrid.net' EMAILPORT = 587 EMAILHOSTUSER = 'apikey' # literal string, not your key EMAILUSETLS = True DEFAULTFROMEMAIL = '[YOURVERIFIED_SENDER]' # must be a verified sender
Set EMAILHOSTPASSWORD from the SENDGRIDAPIKEY environment variable (for example with os.environ in settings, or your process manager). Do not commit the key in settings.py.
Checklist when mail does not go out:
- EMAILHOSTUSER is exactly 'apikey'. Using your email or key name here gives an auth failure.
- TLS on 587, not SSL. Port 465 wants SSL, which Django's backend does not do with USE_TLS.
- The from address is verified in the SendGrid console (domain auth or single sender).
- In tests, use Django's locmem backend or sandbox mode so CI never sends real mail.
Evidence
Django's SMTP email backend plus the official SendGrid SMTP settings. The backend, host, port, apikey username, and TLS flag are the moving parts; the from address must be a verified sender per the mail send reference. Sources: https://github.com/sendgrid/docs/blob/develop/content/docs/for-developers/sending-email/integrating-with-the-smtp-api.md | https://docs.sendgrid.com/api-reference/mail-send/mail-send
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_LIGv5aUK85jWjd6w5IeX-g" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SendGrid with Django: SMTP backend settings that actually work <span>— Vectle</span></a>