【发布时间】:2018-10-30 14:33:04
【问题描述】:
我正在尝试使用我的 Sendgrid 帐户从我的 Django 项目发送一封电子邮件。目前,我通过以下方式发送电子邮件:
import sendgrid
import os
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("test@example.com")
to_email = Email("test@example.com")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
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)
代码取自此链接: https://github.com/sendgrid/sendgrid-python
现在,我想在内容部分执行此操作,而不是发送文本/纯电子邮件,而是发送格式良好的 HTML 电子邮件。最好,我想要某种方式来引用模板并传入上下文。有没有办法做到这一点?谢谢。
【问题讨论】: