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.
First start by adding the following to settings.py:
1SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')23EMAIL_HOST = 'smtp.sendgrid.net'4EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'5EMAIL_HOST_PASSWORD = SENDGRID_API_KEY6EMAIL_PORT = 5877EMAIL_USE_TLS = True
Then to send email you can do the following: Inside yourapp.views.py
1from django.core.mail import send_mail2send_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 library, which utilizes the Web API instead of SMTP as the transport mechanism.