【问题标题】:Django SendGrid not sending email when attaching a template to email将模板附加到电子邮件时,Django SendGrid 不发送电子邮件
【发布时间】:2018-10-04 10:39:13
【问题描述】:

当我发送没有模板的电子邮件时,我会很好地收到电子邮件。当我为模板添加 id 时,我没有收到任何错误,但也没有收到电子邮件。模板设置为活动。我的设置文件中有我的 SENDGRID_API_KEY。我知道它一定是一些非常愚蠢的东西,但似乎无法让它发挥作用。任何帮助将不胜感激。下面代码中的模板 id 被屏蔽了,所以不是实际代码的样子。

from django.views.generic import TemplateView
from django.shortcuts import render
from django.conf import settings
from django.core.mail import send_mail
from django.core.mail import EmailMultiAlternatives


def emailSendGrid(self):
    mail = EmailMultiAlternatives(
        subject="Your Subject from sendGrid",
        body="SendGrid sent This is a simple text email body.",
        from_email="m@test.com",
        to=["martin@test.com"],
        headers={"Reply-To": "m@test.com"}
    )
    # Add template
    mail.template_id = '##############################'

    # Replace substitutions in sendgrid template
    # mail.ad = {'testTag': 'Test email sent from sendgrid with new content'}
    mail.send()

【问题讨论】:

  • 请出示来自settings.py的相关配置,并说明您安装了哪些(如果有)软件包以使用sendgrid。
  • Settings.py added EMAIL_BACKEND = "sgbackend.SendGridBackend" SENDGRID_API_KEY = "key" 当我按照上述代码发送电子邮件时,如果我注释掉 mail.template_id,则会发送电子邮件。但是当我将 mail.template_id 添加回来时,什么也没有发生。没有错误,也没有电子邮件。安装 Django-sendgrid

标签: django sendgrid


【解决方案1】:

问题解决了。最终变成了一个愚蠢的问题。该公司有几个我不知道的 api 密钥。模板已分配给不同的 api 键。道歉

【讨论】:

    猜你喜欢
    • 2016-11-30
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 2022-06-29
    • 1970-01-01
    相关资源
    最近更新 更多