[issue25736] smtplib can't send 8bit encoded utf-8 message

2015-11-26 Thread Ervin Hegedüs

Ervin Hegedüs added the comment:

Here is a workaround:

server.sendmail(mailfrom, rcptto, msg.encode("utf8"))

May be this would be better inside of smtplib?

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25736>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25736] smtplib can't send 8bit encoded utf-8 message

2015-11-26 Thread Ervin Hegedüs

Ervin Hegedüs added the comment:

David,

many thanks for your information.

I think my e-mail format was correct - I've copied it from a maildir, as an 
"email file".

As I wrote, there is a solution: before the code passes the 'msg' argument to 
sendmail() function, it needs to encode() it as "utf-8", then it will be a 
bytestream, instead of unicode (which is the default type of any string in 
Py3). Meanwhile I realized it :).

Thanks again, and sorry for my mistake.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25736>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25736] smtplib can't send 8bit encoded utf-8 message

2015-11-25 Thread Ervin Hegedüs

Changes by Ervin Hegedüs <airw...@gmail.com>:


--
nosy: airween
priority: normal
severity: normal
status: open
title: smtplib can't send 8bit encoded utf-8 message
type: behavior
versions: Python 3.4

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25736>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25736] smtplib can't send 8bit encoded utf-8 message

2015-11-25 Thread Ervin Hegedüs

New submission from Ervin Hegedüs:

Looks like smtplib can send only messages, which contains only 7bit (ascii) 
characters. Here is the example:

# -*- coding: utf8 -*-

import time
import smtplib

mailfrom = "m...@mydomain.com"
rcptto = "m...@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 
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.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25736>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com