Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up email with Sendgrid in Heroku for a Django App

Tags:

I am deploying a Django app on Heroku, and using the Sendgrid addon to send out validation email when a user registers on the site.

I followed the instructions here and pasted the following into settings.py:

EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = 'sendgrid_username' EMAIL_HOST_PASSWORD = 'sendgrid_password' EMAIL_PORT = 587 EMAIL_USE_TLS = True 

However, my app is crashing after registration.

What exactly am I supposed to put for EMAIL_HOST_USER and EMAIL_HOST_PASSWORD?

Under the developer's tab in the sendgrid addon in heroku, it gives me the username app*******@heroku.com, and for password it just says "Your Password". Is the password my Heroku password?

Also, do I need to include DEFAULT_FROM_EMAIL in my settings.py file? And where do I tell Sendgrid what it is?

EDIT: I've set DEBUG = True, and it looks like the error is:

SMTPSenderRefused  (550, 'Cannot receive from specified address <[email protected]>: Unauthenticated senders not allowed', '[email protected]') 

it looks like the problem is happening before Sendgrid does its thing. Do I need to authenticate the email address with Heroku somehow?

like image 913
WarAndPiece Avatar asked Mar 15 '12 15:03

WarAndPiece


People also ask

How to setup SendGrid with Heroku?

Once you have a Heroku app, you can navigate to the Heroku Add-ons page and search for “Twilio SendGrid”. The search will find both the Twilio SendGrid and Twilio SendGrid Marketing Campaigns add-ons. Select Twilio SendGrid. The setup process for Twilio SendGrid Marketing Campaigns is the same.

How does Django integrate with SendGrid?

Setting Up A SendGrid AccountIn the left sidebar, select Settings > API keys > Create API Key. Enter a name for your API key. Choose the API key access whichever is suitable for your requirement. Full Access permissions give the key the ability to perform all the necessary email sending functions.


1 Answers

Within your settings.py include:

import os EMAIL_HOST_USER = os.environ['SENDGRID_USERNAME'] EMAIL_HOST= 'smtp.sendgrid.net' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_PASSWORD = os.environ['SENDGRID_PASSWORD'] 

Edit: changed EMAIL_PASSWORD to EMAIL_HOST_PASSWORD as that's the correct spelling.

like image 73
CraigKerstiens Avatar answered Sep 28 '22 18:09

CraigKerstiens