Skip to content
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

Error sending e-mail with accented characters #83

Closed
lopesandre opened this issue Jul 26, 2013 · 10 comments
Closed

Error sending e-mail with accented characters #83

lopesandre opened this issue Jul 26, 2013 · 10 comments

Comments

@lopesandre
Copy link

Hi,

When I try to subscribe with a non registered user using the form with "Name" and "Email", if I use an accented name, the E-mail is not sent. The error is:

UnicodeEncodeError('ascii', u'Dear Andr\xe9,\r\n\r\nyou, or someone in your name requested a subscription to Gui Chestnut Alert.\r\n\r\nIf you would like to confirm your subscription, please follow this activation link:\r\nhttp://example.com/en/new-season-start-alert/gui-chestnut-alert/subscription/some@email.com/subscribe/activate/1acb3e89050e876268c764fbca80c88db5423a28/\r\n\r\nKind regards,\r\nGui Chestnut Portugal', 9, 10, 'ordinal not in range(128)')

Here I'm trying to send the Name "André"

I've catch this error on views.py, class ActionRequestView, method form_valid

Using Master branch, Django 1.5.1

@jkuczm
Copy link
Contributor

jkuczm commented Jul 27, 2013

I just subscribed in my production environment (with SMTP backend) with name "André" without any problems.

Is this related to previous issue #82? You see "Due to a technical error we were not able to submit ..." in browser and you took this error from the logger?

Which version of python are you using?

Do you have non-default FILE_CHARSET or DEFAULT_CHARSET in your settings.py?

In #82 you mentioned about installing previous version of django-newsletter, does this error occur in fresh install of latest master or in upgraded from previous versions?

May be related to:

@lopesandre
Copy link
Author

Hi jkuczm,

Thank you for you reply.

I've defined in the settings.py

DEFAULT_CHARSET = 'utf-8'
FILE_CHARSET = 'utf-8'

But does not work either with this settings.

To make it work I have to do the described here: http://stackoverflow.com/questions/15831209/django-1-5-unicodeencodeerror-using-attach-alternative-in-emails

There is other way of doing this without changing the source code of Django-newsletter?

Best Regards,

@jkuczm
Copy link
Contributor

jkuczm commented Jul 30, 2013

It's crucial, which version of python are you using?

This looks like a problem in communication between specific versions of Django and specific versions of python. There's a pending Django ticket (20230).

I don't think problem is in django-newsletter.

@dokterbob
Copy link
Collaborator

@lopesandre Don't think this is a problem related to django-newsletter either - but feel free to try and convince me otherwise.

@jkuczm Thanks a lot for your feedback on this one (and others)!

@newearthmartin
Copy link
Contributor

It is a problem with django-newsletter. Facts:

-Unicode is permitted everywhere but in the addresses. From Django docs:

Django’s email framework (in django.core.mail) supports Unicode transparently. You can use Unicode data in the message bodies and any headers. However, you’re still obligated to respect the requirements of the email specifications, so, for example, email addresses should use only ASCII characters.

-Say I have a chinese user of name 李志 and email some_email@gmail.com
-It will fail saying
Message 李志 < some_email@gmail.com > to All Users failed with error: 'ascii' codec can't encode ...

  • So knowing that django is ok with unicode except in the address, there are two options if I have a unicode name for subscription:
  1. I take the name away for that user in my subscription. Then I can-t use the name in the email template 👎
  2. django-newsletter takes the name away when sending the email, but allows me to keep using the name inside the template 👍

Clearly best answer is #2 so that makes it a problem of django-newsletter!

@sergei-maertens
Copy link
Contributor

Fyi, Django < 1.10 had a problem with unicode in e-mail address encodings
on py3. It's fixed in 1.10
On Jun 17, 2016 21:16, "newearthmartin" notifications@github.com wrote:

It is a problem with django-newsletter. Facts:

-Unicode is permitted everywhere but in the addresses. From Django docs:

Django’s email framework (in django.core.mail) supports Unicode
transparently. You can use Unicode data in the message bodies and any
headers. However, you’re still obligated to respect the requirements of the
email specifications, so, for example, email addresses should use only
ASCII characters.

-Say I have a chinese user of name 李志 and email some_email@gmail.com
-It will fail saying
Message 李志 < some_email@gmail.com > to All Users failed with error:
'ascii' codec can't encode ...

So knowing that django is ok with unicode except in the address, there
are two options if I have a unicode name for subscription:

  1. I take the name away for that user in my subscription. Then I can-t
    use the name in the email template 👎
  2. django-newsletter takes the name away when sending the email, but
    allows me to keep using the name inside the template 👍

Clearly best answer is #2
#2 so that makes
it a problem of django-newsletter!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#83 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AFQ01i5BChtlIJFWNtGY1V9TL22IWDOZks5qMvJvgaJpZM4A2Z2t
.

@newearthmartin
Copy link
Contributor

hey, django 1.10 is still in alpha. Most users are not in django1.10. Most probably lot-s of emails are not being sent because of this (and maybe admins dont even realize!)
I have a very small fix for this, I will send you a pull request if you are interested.

@sergei-maertens
Copy link
Contributor

It was just some extra context around the issue :) it should be handled for
1.9 anyway per the compatibility policy
On Jun 17, 2016 21:46, "newearthmartin" notifications@github.com wrote:

hey, django 1.10 is still in alpha. Most users are not in django1.10. Most
probably lot-s of emails are not being sent because of this (and maybe
admins dont even realize!)
I have a very small fix for this, I will send you a pull request if you
are interested.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#83 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AFQ01v8fKrDD1QDVr0l6kCxqTo_qsh-Dks5qMvmkgaJpZM4A2Z2t
.

@newearthmartin
Copy link
Contributor

Ah! I cant upgrade to django 1.9 yet because of my dependencies, so I still need my fix :)
I added a check for the django version in the fix and sent a pull request. Its just a little function, which Im unsure where to put.

@claudep
Copy link
Collaborator

claudep commented Jun 17, 2016

Could you please attach the error traceback so we can see where it fails?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants