Message255401
Looks like smtplib can send only messages, which contains only 7bit (ascii) characters. Here is the example:
# -*- coding: utf8 -*-
import time
import smtplib
mailfrom = "my@mydomain.com"
rcptto = "me@otherdomain.com"
msg = """%s
From: Me <%s>
To: %s
Subject: Plain text e-mail
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
happy New Year
Ευτυχισμένο το Νέο Έτος
明けましておめでとうございます
с Новым годом
""" % (time.strftime('%a, %d %b %Y %H:%M:%S +0100', time.localtime()), mailfrom, rcptto)
server = smtplib.SMTP('localhost')
server.sendmail(mailfrom, rcptto, msg)
server.quit()
With Python2 (Python 2.7), this script finished succesfully. With Python3 (Python 3.4), I've got this execption:
Traceback (most recent call last):
File "8bittest.py", line 28, in <module>
server.sendmail(mailfrom, rcptto, msg)
File "/usr/lib/python3.4/smtplib.py", line 765, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 261-271: ordinal not in range(128)
Basicly, I don't understand, why smtplib allows only ascii encoded messages in Python 3. That worked (and works) in Python 2, and I think, that's the correct behavior. |
|
Date |
User |
Action |
Args |
2015-11-26 07:46:32 | airween | set | recipients:
+ airween |
2015-11-26 07:46:32 | airween | set | messageid: <1448523992.32.0.105956858988.issue25736@psf.upfronthosting.co.za> |
2015-11-26 07:46:32 | airween | link | issue25736 messages |
2015-11-26 07:46:30 | airween | create | |
|