Converted django.core.mail to use 'from django.conf import settings' instead of importing specific settings directly

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2664 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-04-11 03:19:57 +00:00
parent f2aa710f13
commit cd7dbd8f00
1 changed files with 7 additions and 9 deletions

View File

@ -1,6 +1,6 @@
# Use this module for e-mailing.
from django.conf.settings import DEFAULT_FROM_EMAIL, EMAIL_HOST, EMAIL_SUBJECT_PREFIX, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD
from django.conf import settings
from email.MIMEText import MIMEText
import smtplib
@ -14,14 +14,14 @@ 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, auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD):
def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.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, auth_user, auth_password)
def send_mass_mail(datatuple, fail_silently=False, auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD):
def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.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.
@ -30,7 +30,7 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=EMAIL_HOST_USER, au
If auth_user and auth_password are set, they're used to log in.
"""
try:
server = smtplib.SMTP(EMAIL_HOST)
server = smtplib.SMTP(settings.EMAIL_HOST)
if auth_user and auth_password:
server.login(auth_user, auth_password)
except:
@ -41,7 +41,7 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=EMAIL_HOST_USER, au
for subject, message, from_email, recipient_list in datatuple:
if not recipient_list:
continue
from_email = from_email or DEFAULT_FROM_EMAIL
from_email = from_email or settings.DEFAULT_FROM_EMAIL
msg = SafeMIMEText(message)
msg['Subject'] = subject
msg['From'] = from_email
@ -53,10 +53,8 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=EMAIL_HOST_USER, au
def mail_admins(subject, message, fail_silently=False):
"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)
send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], fail_silently)
def mail_managers(subject, message, fail_silently=False):
"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)
send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], fail_silently)