[英]Setting up email with Sendgrid in Heroku for a Django App
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.我正在 Heroku 上部署一个 Django 应用程序,并在用户在网站上注册时使用 Sendgrid 插件发送验证电子邮件。
I followed the instructions here and pasted the following into settings.py
:我按照此处的说明将以下内容粘贴到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
?我到底应该为EMAIL_HOST_USER
和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".在 heroku 的 sendgrid 插件的开发者选项卡下,它给了我用户名app*******@heroku.com
,密码只是说“你的密码”。 Is the password my Heroku password?密码是我的 Heroku 密码吗?
Also, do I need to include DEFAULT_FROM_EMAIL
in my settings.py
file?另外,我是否需要在我的settings.py
文件中包含DEFAULT_FROM_EMAIL
? And where do I tell Sendgrid what it is?我在哪里告诉 Sendgrid 它是什么?
EDIT: I've set DEBUG = True
, and it looks like the error is:编辑:我设置了DEBUG = True
,看起来错误是:
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.看起来问题是在 Sendgrid 做它的事情之前发生的。 Do I need to authenticate the email address with Heroku somehow?我是否需要以某种方式使用 Heroku 验证电子邮件地址?
Within your settings.py include: 在您的settings.py中包括:
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. 编辑:将EMAIL_PASSWORD更改为EMAIL_HOST_PASSWORD,因为这是正确的拼写。
In the intervening 10 years, the above answer has become obsolete.在这之后的 10 年里,上述答案已经过时了。 Sendgrid now uses an API key. Sendgrid 现在使用 API 密钥。
https://docs.sendgrid.com/for-developers/sending-email/django https://docs.sendgrid.com/for-developers/sending-email/django
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'
EMAIL_HOST_PASSWORD = SENDGRID_API_KEY
EMAIL_PORT = 587
EMAIL_USE_TLS = True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.