To: B To: B To: B
خرید بک لینک

Vote count: 0

I am expecting the following code to send an UTF-8 encoded mail.

import email.parser
import smtplib

msg_str = """From: A <a@example.org>
To: B <b@example.org>
Content-Type: text/plain; charset="UTF-8"

Testing UTF-8: – ä."""

msg = email.parser.Parser().parsestr(msg_str)
smtplib.SMTP('localhost').send_message(msg)

However, I am getting this error.

UnicodeEncodeError: 'ascii' codec can't encode character 'u2013' in position 15: ordinal not in range(128)

What is failing here is the flatten call to email.generator.BytesGenerator in pythons smtplib. Shouldn't the email parser fail in the first place if the msg object can't be converted to bytes?

asked 41 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 27 خرداد 1395 ساعت: 15:37

صفحه بندی