Setting up email with Sendgrid in Heroku for a Django App

 ̄綄美尐妖づ 提交于 2019-12-31 08:46:48

问题


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 <info@myapp.com>: Unauthenticated senders not allowed', 'info@myapp.com')

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


回答1:


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.



来源:https://stackoverflow.com/questions/9723494/setting-up-email-with-sendgrid-in-heroku-for-a-django-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!