【发布时间】:2018-10-04 14:12:35
【问题描述】:
有一个烦人的问题。我正在使用 Django 将数据发送到 sendGrid 模板。但是当我添加替换时,我得到一个 HTTP 错误 400:错误请求。如果我不在字典中添加任何内容,它可以按预期通过电子邮件发送模板。所以我确定问题出在标签格式上,我似乎找不到正确的组合
Python
def emailSendGrid(self):
mail = EmailMultiAlternatives(
subject="Your Subject from sendGrid",
body="SendGrid sent This is a simple text email body.",
from_email="anon@test",
to=["dude@test"],
headers={"Reply-To": "anon@test"}
)
# Add template
mail.template_id = '#######################'
# Replace substitutions in sendgrid template
mail.substitutions = {'testTag': 'new content from Django'}
fail_silently = False
mail.send()
SendGrid 模板
<html>
<head>
<title></title>
</head>
<body>
<h3>This is a test email template from sendGrid</h3>
<p> -testTag- </p>
</body>
</html>
这应该很简单,但我已经尝试过我的组合并没有解决。
【问题讨论】:
标签: django python-3.x sendgrid