【发布时间】:2009-09-15 19:22:08
【问题描述】:
我在 Python 3 中使用 smtplib 发送 unicode 字符时遇到问题。这在 3.1.1 中失败,但在 2.5.4 中有效:
import smtplib
from email.mime.text import MIMEText
sender = to = 'ABC@DEF.com'
server = 'smtp.DEF.com'
msg = MIMEText('€10')
msg['Subject'] = 'Hello'
msg['From'] = sender
msg['To'] = to
s = smtplib.SMTP(server)
s.sendmail(sender, [to], msg.as_string())
s.quit()
我尝试了文档中的一个示例,但也失败了。 http://docs.python.org/3.1/library/email-examples.html,将目录内容作为 MIME 消息发送示例
有什么建议吗?
【问题讨论】:
-
澄清一下,在 2.5.4 中,它发送时没有错误消息,但将 '€' 替换为 '?'。
标签: python email unicode python-3.x smtplib