我想发送格式化的电子邮件,其中包含纯文本替代方法:
body_plain = "content of the email with variables %(var1)s %(var2)s etc"
body_html = """"<!DOCTYPE>
<html>
<body><p>content of the email with variables %(var1)s %(var2)s etc</p></body>
</html>"""
vars = {'var1': var1, 'var2': var2}
使用smtplib,我只需传递以下信息:
msg = MIMEMultipart('alternative')
msg["Subject"] = subject
msg["From"] = sender
msg["To"] = recipients[0]
msg.attach(MIMEText(body_plain % vars, 'plain')) # format 1 : text
msg.attach(MIMEText(body_html % vars, 'html')) # format 2 : html
为:
client.send_message(msg)
但是pyramid_mailer呢?我只是成功地将单纯的身体单独传递给了“身体”论点:
message = Message(subject=subject, sender=sender, recipients=recipients, body=?)
mailer = get_mailer(request)
mailer.send_immediately(message)
答案 0 :(得分:0)
确定发现到目前为止还没有MIMEMultipart / MIMEText,因为&#39; body&#39;和&#39; html&#39;来自pyramid_mailer.message的消息的参数就足够了
message = Message(subject=subject, sender=sender, recipients=recipients, body=body_plaintext, html=body_html)