我使用的是Django / Sendgrid / Heroku设置,该设置运行良好,但没有明显原因就停止了。
我的django设置:
EMAIL_HOST="smtp.sendgrid.net"
EMAIL_HOST_PASSWORD="..."
EMAIL_HOST_USER="..."
EMAIL_PORT=587
EMAIL_USE_TLS=True
使用此设置,如果我使用django库发送简单的电子邮件...
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
from_email_address,
[to_email_address],
fail_silently=False,
)
我收到此错误
--> SMTPServerDisconnected: Connection unexpectedly closed
我仍然可以使用sendgrid python库发送电子邮件
import sendgrid
sg = sendgrid.SendGridAPIClient(apikey)
sg.send(data)
我有什么想念的吗?
刚刚想通了:Sendgrid通过SENDGRID_PASSWORD
Heroku环境变量动态提供密码。但是,用于电子邮件设置的变量为EMAIL_HOST_PASSWORD
,在更改密码后未更新。
确保两个变量都相同