mirror of https://github.com/django/django.git
Fixed #1235: email sent from {{{django.core.mail}}} will now be encoded 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
This commit is contained in:
parent
5c0e4f3908
commit
aa11b3ea50
|
@ -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 @@ class SafeMIMEText(MIMEText):
|
|||
"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)
|
||||
|
|
|
@ -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()
|
||||
===========
|
||||
|
|
Loading…
Reference in New Issue