# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
msg['From'] = me
msg['To'] = you
...
# Record the MIME types of both parts - text/plain and text/html.
# ... text and html are strings with appropriate content.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
如果您从sourceforge引用
libgmail
,则需要用email module组合消息。在将HTML消息生成为MIME document,并将其作为multipart MIME message的一部分。当您有一个完全构造的多部分MIME时,将其作为一个字符串传递给
libgmail
构造函数,使用to.as_string()
方法。在example in the doc包含类似要求的代码:
相关问题 更多 >
编程相关推荐