I think it would be very useful if it was possible to send e-mail (using
'django.core.mail') in something different than 'us-ascii', for example,
in 'utf-8' by default. I have tried to implement this:
=========
Index: django/conf/global_settings.py
===================================================================
--- django/conf/global_settings.py (revision 1983)
+++ django/conf/global_settings.py (working copy)
@@ -68,6 +68,9 @@
DEFAULT_CONTENT_TYPE = 'text/html'
DEFAULT_CHARSET = 'utf-8'
+# Default charset used for sending e-mail messages.
+DEFAULT_EMAIL_CHARSET = 'utf-8'
+
# E-mail address that error messages come from.
SERVER_EMAIL = 'root@localhost'
Index: django/core/mail.py
===================================================================
--- django/core/mail.py (revision 1983)
+++ django/core/mail.py (working copy)
@@ -1,7 +1,9 @@
# Use this module for e-mailing.
from django.conf.settings import DEFAULT_FROM_EMAIL, EMAIL_HOST, EMAIL_SUBJECT_PREFIX
+from django.conf.settings import DEFAULT_EMAIL_CHARSET
from email.MIMEText import MIMEText
+from email.Header import Header
import smtplib
class BadHeaderError(ValueError):
@@ -39,8 +41,8 @@
if not recipient_list:
continue
from_email = from_email or DEFAULT_FROM_EMAIL
- msg = SafeMIMEText(message)
- msg['Subject'] = subject
+ msg = SafeMIMEText(message, 'plain', DEFAULT_EMAIL_CHARSET)
+ msg['Subject'] = str(Header(subject, DEFAULT_EMAIL_CHARSET)).replace('\n', '').replace('\r', '')
msg['From'] = from_email
msg['To'] = ', '.join(recipient_list)
server.sendmail(from_email, recipient_list, msg.as_string())
=========
--
Igor Goryachev E-Mail/Jabber: ig...@goryachev.org
> I think it would be very useful if it was possible to send e-mail (using
> 'django.core.mail') in something different than 'us-ascii', for example,
> in 'utf-8' by default. I have tried to implement this:
I have reworked it a bit and submitted patch Ticket #1235.
Any feedback?
Makes sense given the recent push for making the Django core UTF8. The
majority of the MUA's out there already know how to support UTF8 in
emails. It will only increase the satisfaction for the non-English
speaking populace (which outnumbers the native English speakers). Even
closely related languages to English like Dutch, German, Norwegian,
Swedish, and Danish already need accents, us-ascii does NOT provide
these.
+1
--
Jeroen Ruigrok van der Werven
>Makes sense given the recent push for making the Django core UTF8.
>
No, recent push is to make Django core Unicode (arrays of 2-byte
normalized characters). Django now is in UTF-8 (Unicode encoded to be
passed as single-byte strings) and this is the exact problem: it's
harder to work with UTF-8 then with Unicode.
> The
>majority of the MUA's out there already know how to support UTF8 in
>emails.
>
In fact for emails I'm not that sure. People often are forced to read
email through old-style web-based mail readers that don't have any
notion of unicode in general and utf-8 in particular, admins set them up
to work in some legacy 1-byte encoding. This is why there is a
preference setting in Igor's patch.
well, it's not always 2bytes (usually it's 4bytes).
(sorry, couldn't resist :)
gabor