【发布时间】:2018-08-12 13:01:04
【问题描述】:
在名称中使用非 ascii 字符时,python smtplib 出现问题。部分错误代码 - 是
server does not advertise the required SMTPUTF8 capability
我已经在网上查了解决方案,也在 stackoverflow 中查看了没有解决方案。
使用相同的
smtp
在其他具有相同发件人名称的邮件客户端上它可以工作,所以我认为这可以通过代码解决,因为我无法编辑服务器配置。
请提供解决方案指南或示例以帮助解决此问题。
请参阅下面带有回溯的代码的 sn-p。
# the problem is this line below. How do I make it work regardless
# since i have no means of advertising smtputf8 from there server.
# Thunderbird doesn't have problem with the name when used as client.
data['from_name'] = "Böy" # problem is the ö
data['from_email'] = "user@example.com"
msg = MIMEMultipart()
msg['To'] = "{to_name} <{to_email}>".format(**data)
msg['From'] = "{} <{}>".format(data['from_name'], data['from_email'])
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach(MIMEText(body, 'html'))
smtp_server.send_message(msg) # exception is raised here
追溯:
`Traceback (most recent call last):
File "Emailer.py", line 460, in <module>
main(args)
File "Emailer.py", line 447, in main
sender.send()
File "Emailer.py", line 386, in send
smtp_server.send_message(msg)
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 952, in send_message
"One or more source or delivery addresses require"
smtplib.SMTPNotSupportedError: One or more source or delivery addresses require internationalized email support, but the server does not advertise the required SMTPUTF8 capability`
【问题讨论】:
-
Thunderbird 最有可能使用 RFC2047 封装对字符串进行编码;因此它不会尝试将裸 UTF-8 发送到不支持此功能的服务器。
-
@tripleee 好建议,我会看看我能不能走那条路。不介意您是否可以对此进行更多说明,因为消息正文已经是 utf8。怀疑我可以结合两种编码
标签: python python-3.x email utf-8 smtplib