在Heroku中使用Sendgrid设置Django应用程序的电子邮件 [英] Setting up email with Sendgrid in Heroku for a Django App

查看:152
本文介绍了在Heroku中使用Sendgrid设置Django应用程序的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上部署了一个Django应用程序,当用户在网站上注册时,使用Sendgrid插件来发送验证电子邮件。

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.

我遵循说明这里,并将以下内容粘贴到 settings.py 中:

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.

我应该为 EMAIL_HOST_USER EMAIL_HOST_PASSWORD

在英雄的sendgrid插件的开发人员标签下,它给了我的用户名 app ******* @ heroku .com ,而对于密码,它只是说你的密码。密码是我的Heroku密码?

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?

此外,我需要在我的 settings.py DEFAULT_FROM_EMAIL c $ c>文件?我在哪里可以告诉Sendgrid是什么?

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

编辑:我设置了 DEBUG = True ,它看起来像错误是:

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')

在Sendgrid做它的事情之前,问题正在发生。我需要用Heroku来验证电子邮件地址吗?

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

推荐答案

在您的settings.py中包括:

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']

编辑:将EMAIL_PASSWORD更改为EMAIL_HOST_PASSWORD,因为这是正确的拼写。

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

这篇关于在Heroku中使用Sendgrid设置Django应用程序的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆