[issue4403] regression from 2.6: smtplib.py requiring ascii for sending messages

2008-11-23 Thread August Mueller

New submission from August Mueller <[EMAIL PROTECTED]>:

smtplib requires that messages being sent be in ascii, and throws an exception 
otherwise.  
Python 2.6 doesn't require this.  Here's the diff where it was introduced:
http://svn.python.org/view/python/branches/py3k/Lib/smtplib.py?rev=59102&r1=58495&r2=59102

Is there a good reason for this?  I use python for a webstore, and send out 
emails for folks 
with multibyte names (for instance, if a name has an umlaut).

Here's a code snippit + exception:

Python 3.0rc3 (r30rc3:67312, Nov 22 2008, 18:45:57) 
[GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import smtplib
>>> server = smtplib.SMTP("localhost")
>>> server.sendmail("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "Ümlaut")
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/mu.org/home/gus/unix/python3/lib/python3.0/smtplib.py", line 713, 
in sendmail
(code,resp) = self.data(msg)
  File "/home/mu.org/home/gus/unix/python3/lib/python3.0/smtplib.py", line 481, 
in data
self.send(q)
  File "/home/mu.org/home/gus/unix/python3/lib/python3.0/smtplib.py", line 305, 
in send
s = s.encode("ascii")
UnicodeEncodeError: 'ascii' codec can't encode character '\xdc' in position 0: 
ordinal not in 
range(128)

Is there a workaround or a new way of using it?  I couldn't seem to find it.

Thanks!

--
components: Library (Lib)
messages: 76295
nosy: ccgus
severity: normal
status: open
title: regression from 2.6: smtplib.py requiring ascii for sending messages
versions: Python 3.0

___
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue4403>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4403] regression from 2.6: smtplib.py requiring ascii for sending messages

2008-11-23 Thread August Mueller

August Mueller <[EMAIL PROTECTED]> added the comment:

Encoding the message first doesn't work either:

>>> import smtplib
>>> server = smtplib.SMTP("localhost")
>>> server.sendmail("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", 
>>> "Ümlaut".encode("UTF-8"))
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/mu.org/home/gus/unix/python3/lib/python3.0/smtplib.py", line 713, 
in sendmail
(code,resp) = self.data(msg)
  File "/home/mu.org/home/gus/unix/python3/lib/python3.0/smtplib.py", line 477, 
in data
q = quotedata(msg)
  File "/home/mu.org/home/gus/unix/python3/lib/python3.0/smtplib.py", line 157, 
in quotedata
re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data))
  File "/home/mu.org/home/gus/unix/python3/lib/python3.0/re.py", line 165, in 
sub
return _compile(pattern, 0).sub(repl, string, count)
TypeError: can't use a string pattern on a bytes-like object

Should a check be done in data() first, before it tries to try string 
operations on it?

___
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue4403>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4403] regression from 2.6: smtplib.py requiring ascii for sending messages

2008-11-25 Thread August Mueller

August Mueller <[EMAIL PROTECTED]> added the comment:

For completeness, if anyone runs across this in the future, the following seems 
to work for sending utf-8 mail 
in python 3:

import smtplib
import email.mime.text

msg = email.mime.text.MIMEText("Ümlaut", _charset="UTF-8")

smtp = smtplib.SMTP('localhost')
smtp.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', "Subject: This is your 
mail\n" + msg.as_string())
smtp.quit()

___
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue4403>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com