【发布时间】: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