Code

Ticket #3448: core_mail_help-v2.diff

File core_mail_help-v2.diff, 2.9 KB (added by Per Jonsson <poj@…>, 7 years ago)
Line 
1Index: django/core/mail.py
2===================================================================
3--- django/core/mail.py (revision 4557)
4+++ django/core/mail.py (working copy)
5@@ -33,21 +33,34 @@
6             val = Header(val, settings.DEFAULT_CHARSET)
7         MIMEText.__setitem__(self, name, val)
8 
9-def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD):
10+def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None):
11     """
12     Easy wrapper for sending a single message to a recipient list. All members
13     of the recipient list will see the other recipients in the 'To' field.
14+
15+    If auth_user is None, the EMAIL_HOST_USER setting is used.
16+    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
17     """
18+    if auth_user is None:
19+        auth_user=settings.EMAIL_HOST_USER
20+    if auth_password is None:
21+        auth_password=settings.EMAIL_HOST_PASSWORD
22     return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently, auth_user, auth_password)
23 
24-def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD):
25+def send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None):
26     """
27     Given a datatuple of (subject, message, from_email, recipient_list), sends
28     each message to each recipient list. Returns the number of e-mails sent.
29 
30     If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
31     If auth_user and auth_password are set, they're used to log in.
32+    If auth_user is None, the EMAIL_HOST_USER setting is used.
33+    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
34     """
35+    if auth_user is None:
36+        auth_user=settings.EMAIL_HOST_USER
37+    if auth_password is None:
38+        auth_password=settings.EMAIL_HOST_PASSWORD
39     try:
40         server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
41         if auth_user and auth_password:
42Index: docs/email.txt
43===================================================================
44--- docs/email.txt      (revision 4557)
45+++ docs/email.txt      (working copy)
46@@ -34,8 +34,8 @@
47 ``django.core.mail.send_mail()``. Here's its definition::
48 
49     send_mail(subject, message, from_email, recipient_list,
50-        fail_silently=False, auth_user=EMAIL_HOST_USER,
51-        auth_password=EMAIL_HOST_PASSWORD)
52+        fail_silently=False, auth_user=None,
53+        auth_password=None)
54 
55 The ``subject``, ``message``, ``from_email`` and ``recipient_list`` parameters
56 are required.
57@@ -65,7 +65,7 @@
58 Here's the definition::
59 
60     send_mass_mail(datatuple, fail_silently=False,
61-        auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD):
62+        auth_user=None, auth_password=None):
63 
64 ``datatuple`` is a tuple in which each element is in this format::
65