我有渲染HTML文本的mandrill模板。我正在通过smtplib python进行API调用,并将消息发送到mandrill,如下所示: -
import smtplib
import json
class Email():
def __init__ (self):
pass
def send_mail(self, to, subject, message):
sender = '.....'
passwd = '.....'
server = smtplib.SMTP('smtp.mandrillapp.com', 587)
server.ehlo()
server.starttls()
server.login(sender, passwd)
template_content = {"template_content": [
{
"name": "title",
"content": "<h2>Your Order is Complete</h2>"
},
{
"name": "main",
"content": "We appreciate your business. Your order information is below."
}
]}
body = '\r\n'.join([
'To: %s' % to,
# 'From: %s' % sender,
'X-MC-Template: %s' % "master|main",
# 'X-MC-Metadata: %s' % json.dumps(template_content),
'Subject: %s' % subject,
'', message
])
try:
server.sendmail(sender, [to], body)
server.quit()
return True
except:
server.quit()
return False
我想以动态方式生成内容(消息正文为HTML),并将其作为HTML发送给我发送的电子邮件。怎么办呢?