Skip to contentSkip to navigationSkip to topbar
Page tools
Looking for more inspiration?Visit the

Django


To send email from a Django application with SendGrid, configure Django's built-in email settings to use SendGrid's SMTP relay. Django, a Python web framework, provides a built-in way to send email that works with SendGrid as the delivery service.

For more detail about sending email over SMTP with Django, see the Django email documentation(link takes you to an external page).

First start by adding the following to settings.py:

1
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
2
3
EMAIL_HOST = 'smtp.sendgrid.net'
4
EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'
5
EMAIL_HOST_PASSWORD = SENDGRID_API_KEY
6
EMAIL_PORT = 587
7
EMAIL_USE_TLS = True

Then to send email you can do the following: Inside yourapp.views.py

1
from django.core.mail import send_mail
2
send_mail('Subject here', 'Here is the message.', 'from@example.com', ['to@example.com'], fail_silently=False)

Customize the subject, message, sender email address, and recipients as needed for your use case.

(information)

Info

You may also send emails with Django by using the django-sendgrid-v5(link takes you to an external page) library, which utilizes the Web API instead of SMTP as the transport mechanism.