Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #1235: email sent from {{{django.core.mail}}} will now be encod…

…ed using

the value of the {{{DEFAULT_CHARSET}}} setting. Thanks, igor@goryachev.org and akaihola.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@2901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aa11b3ea503ba1e6247e1629aa13f2752f32e3a9 1 parent 5c0e4f3
@jacobian jacobian authored
Showing with 11 additions and 1 deletion.
  1. +4 −1 django/core/mail.py
  2. +7 −0 docs/email.txt
View
5 django/core/mail.py
@@ -2,6 +2,7 @@
from django.conf import settings
from email.MIMEText import MIMEText
+from email.Header import Header
import smtplib
class BadHeaderError(ValueError):
@@ -12,6 +13,8 @@ def __setitem__(self, name, val):
"Forbids multi-line headers, to prevent header injection."
if '\n' in val or '\r' in val:
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
+ if name == "Subject":
+ val = Header(val, settings.DEFAULT_CHARSET)
MIMEText.__setitem__(self, name, val)
def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD):
@@ -42,7 +45,7 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST
if not recipient_list:
continue
from_email = from_email or settings.DEFAULT_FROM_EMAIL
- msg = SafeMIMEText(message)
+ msg = SafeMIMEText(message, 'plain', settings.DEFAULT_CHARSET)
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = ', '.join(recipient_list)
View
7 docs/email.txt
@@ -19,6 +19,13 @@ In two lines::
send_mail('Subject here', 'Here is the message.', 'from@example.com',
['to@example.com'], fail_silently=False)
+
+.. note::
+
+ The character set of email sent with ``django.core.mail`` will be set to
+ the value of your `DEFAULT_CHARSET setting`_.
+
+.. _DEFAULT_CHARSET setting: ../settings/#DEFAULT_CHARSET
send_mail()
===========
Please sign in to comment.
Something went wrong with that request. Please try again.