lavr / python-emails

Modern python library for emails
http://python-emails.readthedocs.org
Other
405 stars 54 forks source link

Got UnicodeEncodeError: on python 3.5 #117

Closed kalombos closed 6 years ago

kalombos commented 6 years ago

Here is the code:

        from emails import Message
        message = Message(
            subject='test',
            html='<html>Привет</html>', mail_from="test@test.com"
        )

        message.send(to='test@test.com')

and the error:

  File "manage.py", line 121, in created_eqs_notify
    message.send(to='test@test.com')
  File "/home/kalombo/.virtualenvs/dev3/lib/python3.5/site-packages/emails/message.py", line 404, in send
    return smtp.sendmail(**params)
  File "/home/kalombo/.virtualenvs/dev3/lib/python3.5/site-packages/emails/backend/smtp/backend.py", line 119, in sendmail
    rcpt_options=rcpt_options)
  File "/home/kalombo/.virtualenvs/dev3/lib/python3.5/site-packages/emails/backend/smtp/backend.py", line 80, in wrapper
    return func(*args, **kwargs)
  File "/home/kalombo/.virtualenvs/dev3/lib/python3.5/site-packages/emails/backend/smtp/backend.py", line 103, in _send
    return client.sendmail(**kwargs)
  File "/home/kalombo/.virtualenvs/dev3/lib/python3.5/site-packages/emails/backend/smtp/client.py", line 105, in sendmail
    (code, resp) = self.data(msg)
  File "/usr/lib/python3.5/smtplib.py", line 562, in data
    msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 679-684: ordinal not in range(128)
lavr commented 6 years ago

Can you give more information on you environment? I can't reproduce on my:

$  python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from emails import Message
>>> message = Message(
...     subject='test',
...     html='<html>Привет</html>', mail_from="test@test.com"
... )
>>> message.send(to='test@test.com')
<emails.backend.SMTPResponse status_code=250 status_text=b'2.0.0 Ok: queued as E6FA0161878'>
>>> import emails; emails.__version__
'0.5.15'
kalombos commented 6 years ago

Yeah, you are right, i didn't get errors in console too. But i still have this error in some cases in my flask application. I'll analyze these cases and tell you about results. For the moment i found that error raising depends on place where i import package.

kalombos commented 6 years ago

It was because of flask-mail package when i removed it from application your package worked fine. Sorry for the wrong issue and thanks for the help.