【问题标题】:Django, Mail not sending. SendgridDjango,邮件未发送。发送网格
【发布时间】:2017-07-31 13:09:32
【问题描述】:

我正在尝试通过发送网格从网站的联系表格向管理员发送邮件。由于某种原因,电子邮件未送达

这里是 view.py

def contact(request):
title = 'Contact'
form = contactForm(request.POST or None)
confirm_message = None

if form.is_valid():
    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
    name = form.cleaned_data['name']
    comment = form.cleaned_data['comment']
    subject = 'Message from **'
    content = '%s %s' %(comment, name)
    from_email = form.cleaned_data['email']
    to_email = Email("***")
    try:
        mail = Mail(from_email, subject, to_email, content)
        response = sg.client.mail.send.post(request_body=mail.get())
    except:
        title="Sorry!"
        confirm_message = "Error sending message, Please try after sometime. Thank you!"
    title="Thanks"
    confirm_message = "Thanks for the message, We will get right back to you."
    form = None

context = {'title': title, 'form':form, 'confirm_message': confirm_message,}
template = "contact.html"
return render(request,template,context)

settings.py

EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = '**'
EMAIL_HOST_PASSWORD = '***'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = "sgbackend.SendGridBackend"

电子邮件是在 zoho 中设置的。我无法收到任何电子邮件

【问题讨论】:

    标签: django sendgrid


    【解决方案1】:

    首先确保您已安装 sendgrid-django。然后在您的设置中,您似乎没有 sendgrid API 密钥。尝试在下面添加以下内容:

    SENDGRID_API_KEY = "您的 SendGrid API 密钥"

    看看这是否有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 2011-03-02
      • 2016-01-28
      • 1970-01-01
      • 2017-02-02
      • 2019-10-31
      相关资源
      最近更新 更多