New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-ascii encoding for email subject and body #338

Closed
cocasema opened this Issue Feb 16, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@cocasema

cocasema commented Feb 16, 2016

Current implementation of SMTPMailHandler fails to send non-ascii messages.
This could be fixed using MIMEText.

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Feb 16, 2016

Member

@cocasema thank you for the report. Would it be possible to add a MCVE? If not, then atleast an example of the subject/body that you're trying to send.

Thanks!

Member

derks commented Feb 16, 2016

@cocasema thank you for the report. Would it be possible to add a MCVE? If not, then atleast an example of the subject/body that you're trying to send.

Thanks!

@derks derks added the bug label Feb 16, 2016

@derks derks added this to the 2.8.0 Stable milestone Feb 16, 2016

@derks derks self-assigned this Feb 16, 2016

@cocasema

This comment has been minimized.

Show comment
Hide comment
@cocasema

cocasema Feb 16, 2016

Sure. Here is a small cement app to repro the issue and modified SMTPMailHandler to handle it.
https://github.com/cocasema/mcve/tree/master/cement-338

Exception:

Traceback (most recent call last):
  File "./smtp_utf.py", line 17, in <module>
    app.send()
  File "./smtp_utf.py", line 13, in send
    self.mail.send(body='Текст', subject='Тема')
  File "/home/<user>/.virtualenvs/<venv>/lib/python3.4/site-packages/cement/ext/ext_smtp.py", line 233, in send
    msg)
  File "/usr/lib/python3.4/smtplib.py", line 764, in sendmail
    msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 63-66: ordinal not in range(128)

cocasema commented Feb 16, 2016

Sure. Here is a small cement app to repro the issue and modified SMTPMailHandler to handle it.
https://github.com/cocasema/mcve/tree/master/cement-338

Exception:

Traceback (most recent call last):
  File "./smtp_utf.py", line 17, in <module>
    app.send()
  File "./smtp_utf.py", line 13, in send
    self.mail.send(body='Текст', subject='Тема')
  File "/home/<user>/.virtualenvs/<venv>/lib/python3.4/site-packages/cement/ext/ext_smtp.py", line 233, in send
    msg)
  File "/usr/lib/python3.4/smtplib.py", line 764, in sendmail
    msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 63-66: ordinal not in range(128)
@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Feb 16, 2016

Member

@cocasema awesome! This is super helpful. Will get it into 2.8.0 before I complete and push it out.

Member

derks commented Feb 16, 2016

@cocasema awesome! This is super helpful. Will get it into 2.8.0 before I complete and push it out.

derks added a commit that referenced this issue Feb 22, 2016

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Feb 22, 2016

Member

This is now resolved in master, though it only fixes py3. Seems that py2 doesn't even open the file if non-ascii characters exist.

Member

derks commented Feb 22, 2016

This is now resolved in master, though it only fixes py3. Seems that py2 doesn't even open the file if non-ascii characters exist.

@derks derks closed this Feb 22, 2016

@cocasema

This comment has been minimized.

Show comment
Hide comment
@cocasema

cocasema Feb 23, 2016

Thank you!

cocasema commented Feb 23, 2016

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment