diff --git a/AUTHORS b/AUTHORS
index 1e061703c60..1c8036b74ac 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -56,7 +56,6 @@ answer newbie questions, and generally made Django that much better:
gandalf@owca.info
Baishampayan Ghose
Espen Grindhaug
- Gustavo Picon
Brant Harris
hipertracker@gmail.com
Ian Holsman
@@ -68,6 +67,7 @@ answer newbie questions, and generally made Django that much better:
Russell Keith-Magee
Garth Kidd
Sune Kirkeby
+ Bruce Kroeze
lakin.wecker@gmail.com
Stuart Langridge
Eugene Lazutkin
@@ -88,6 +88,7 @@ answer newbie questions, and generally made Django that much better:
oggie rob
pgross@thoughtworks.com
phaedo
+ Gustavo Picon
Luke Plant
plisk
Daniel Poelzleithner
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index febd821e6a6..dca31188802 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -87,6 +87,10 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
+# Optional SMTP authentication information for EMAIL_HOST.
+EMAIL_HOST_USER = ''
+EMAIL_HOST_PASSWORD = ''
+
# List of strings representing installed apps.
INSTALLED_APPS = ()
diff --git a/django/core/mail.py b/django/core/mail.py
index 5c31c4d8126..a1e491dbc77 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)
diff --git a/docs/email.txt b/docs/email.txt
index c39fbbd114f..8159536d1e1 100644
--- a/docs/email.txt
+++ b/docs/email.txt
@@ -26,10 +26,12 @@ The send_mail function
The simplest way to send e-mail is using the function
``django.core.mail.send_mail``. Here's its definition::
- send_mail(subject, message, from_email, recipient_list, fail_silently=False)
+ send_mail(subject, message, from_email, recipient_list,
+ fail_silently=False, auth_user=EMAIL_HOST_USER,
+ auth_password=EMAIL_HOST_PASSWORD)
-All parameters are required except for ``fail_silently``, which is ``False`` by
-default.
+The ``subject``, ``message``, ``from_email`` and ``recipient_list`` parameters
+are required.
* ``subject``: A string.
* ``message``: A string.
@@ -40,6 +42,13 @@ default.
* ``fail_silently``: A boolean. If it's ``False``, ``send_mail`` will raise
an ``smtplib.SMTPException``. See the `smtplib docs`_ for a list of
possible exceptions, all of which are subclasses of ``SMTPException``.
+ * ``auth_user``: **New in Django development version.** The optional
+ username to use to authenticate to the SMTP server. If this isn't
+ provided, Django will use the value of the ``EMAIL_HOST_USER`` setting.
+ * ``auth_password``: **New in Django development version.** The optional
+ password to use to authenticate to the SMTP server. If this isn't
+ provided, Django will use the value of the ``EMAIL_HOST_PASSWORD``
+ setting.
.. _smtplib docs: http://www.python.org/doc/current/lib/module-smtplib.html
@@ -49,13 +58,16 @@ The send_mass_mail function
``django.core.mail.send_mass_mail`` is intended to handle mass e-mailing.
Here's the definition::
- send_mass_mail(datatuple, fail_silently=False):
+ send_mass_mail(datatuple, fail_silently=False,
+ auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD):
``datatuple`` is a tuple in which each element is in this format::
(subject, message, from_email, recipient_list)
-``fail_silently`` has the same function as in ``send_mail()``.
+``fail_silently``, ``auth_user`` and ``auth_password`` have the same functions
+as in ``send_mail()``. Note that ``auth_user`` and ``auth_password`` are only
+available in the Django development version.
Each separate element of ``datatuple`` results in a separate e-mail message.
As in ``send_mail()``, recipients in the same ``recipient_list`` will all see
diff --git a/docs/settings.txt b/docs/settings.txt
index af277f4ca2c..256a1b950cc 100644
--- a/docs/settings.txt
+++ b/docs/settings.txt
@@ -334,6 +334,30 @@ Default: ``'localhost'``
The host to use for sending e-mail.
+EMAIL_HOST_PASSWORD
+-------------------
+
+Default: ``''`` (Empty string)
+
+**New in Django development version.**
+
+Username to use for the SMTP server defined in ``EMAIL_HOST``. If empty,
+Django won't attempt authentication.
+
+See also ``EMAIL_HOST_USER``.
+
+EMAIL_HOST_USER
+---------------
+
+Default: ``''`` (Empty string)
+
+**New in Django development version.**
+
+Username to use for the SMTP server defined in ``EMAIL_HOST``. If empty,
+Django won't attempt authentication.
+
+See also ``EMAIL_HOST_PASSWORD``.
+
EMAIL_SUBJECT_PREFIX
--------------------