summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-03-22 19:47:15 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-03-22 19:47:15 +0000
commitfe24eca81aee4c75365101430940d2fbb5979bc6 (patch)
tree06f7be1394241008b6a1e012f82232e80437c7d3 /django/core
parente67f1a680d8780b52c2a1020c37b51c5455b0d4b (diff)
Fixed #1529 -- Added support for authenticated SMTP to django.core.mail. Thanks, Bruce Kroeze
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2548 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/mail.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/django/core/mail.py b/django/core/mail.py
index 5c31c4d812..a1e491dbc7 100644
--- a/django/core/mail.py
+++ b/django/core/mail.py
@@ -1,6 +1,6 @@
# 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_FROM_EMAIL, EMAIL_HOST, EMAIL_SUBJECT_PREFIX, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD
from email.MIMEText import MIMEText
import smtplib
@@ -14,22 +14,25 @@ class SafeMIMEText(MIMEText):
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
MIMEText.__setitem__(self, name, val)
-def send_mail(subject, message, from_email, recipient_list, fail_silently=False):
+def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD):
"""
Easy wrapper for sending a single message to a recipient list. All members
of the recipient list will see the other recipients in the 'To' field.
"""
- return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently)
+ return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently, auth_user, auth_password)
-def send_mass_mail(datatuple, fail_silently=False):
+def send_mass_mail(datatuple, fail_silently=False, auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD):
"""
Given a datatuple of (subject, message, from_email, recipient_list), sends
each message to each recipient list. Returns the number of e-mails sent.
If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
+ If auth_user and auth_password are set, they're used to log in.
"""
try:
server = smtplib.SMTP(EMAIL_HOST)
+ if auth_user and auth_password:
+ server.login(auth_user, auth_password)
except:
if fail_silently:
return
@@ -49,11 +52,11 @@ def send_mass_mail(datatuple, fail_silently=False):
return num_sent
def mail_admins(subject, message, fail_silently=False):
- "Sends a message to the admins, as defined by the ADMINS constant in settings.py."
+ "Sends a message to the admins, as defined by the ADMINS setting."
from django.conf.settings import ADMINS, SERVER_EMAIL
send_mail(EMAIL_SUBJECT_PREFIX + subject, message, SERVER_EMAIL, [a[1] for a in ADMINS], fail_silently)
def mail_managers(subject, message, fail_silently=False):
- "Sends a message to the managers, as defined by the MANAGERS constant in settings.py"
+ "Sends a message to the managers, as defined by the MANAGERS setting."
from django.conf.settings import MANAGERS, SERVER_EMAIL
send_mail(EMAIL_SUBJECT_PREFIX + subject, message, SERVER_EMAIL, [a[1] for a in MANAGERS], fail_silently)