我正在尝试使用python django使用sendgrid发送电子邮件。由于某些原因,电子邮件已被发送,但其中没有html内容。我可能做错了什么?
def sendemail(sender,recipient,subject,content,url):
sg = sendgrid.SendGridAPIClient(apikey="")
from_email = Email(sender)
to_email = Email(recipient)
subject = subject
objects = {
"message":content,
"domain":url
}
html_content = get_template('sendemail.html').render(objects)
print ('htmlcontent',html_content)
content = Content("text/html",html_content)
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
答案 0 :(得分:0)
我认为您还必须设置文本/纯文本内容。
您可以尝试这样的事情:
mail = Mail(from_email, subject, to_email)
mail.add_content(Content("text/plain", "plain message"))
mail.add_content(Content("text/html", html_content ))