mirror of
https://github.com/django/django.git
synced 2025-01-19 06:43:15 +00:00
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:
parent
f2aa710f13
commit
cd7dbd8f00
@ -1,6 +1,6 @@
|
|||||||
# Use this module for e-mailing.
|
# 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
|
from email.MIMEText import MIMEText
|
||||||
import smtplib
|
import smtplib
|
||||||
|
|
||||||
@ -14,14 +14,14 @@ class SafeMIMEText(MIMEText):
|
|||||||
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
|
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
|
||||||
MIMEText.__setitem__(self, name, val)
|
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
|
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.
|
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)
|
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
|
Given a datatuple of (subject, message, from_email, recipient_list), sends
|
||||||
each message to each recipient list. Returns the number of e-mails sent.
|
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.
|
If auth_user and auth_password are set, they're used to log in.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
server = smtplib.SMTP(EMAIL_HOST)
|
server = smtplib.SMTP(settings.EMAIL_HOST)
|
||||||
if auth_user and auth_password:
|
if auth_user and auth_password:
|
||||||
server.login(auth_user, auth_password)
|
server.login(auth_user, auth_password)
|
||||||
except:
|
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:
|
for subject, message, from_email, recipient_list in datatuple:
|
||||||
if not recipient_list:
|
if not recipient_list:
|
||||||
continue
|
continue
|
||||||
from_email = from_email or DEFAULT_FROM_EMAIL
|
from_email = from_email or settings.DEFAULT_FROM_EMAIL
|
||||||
msg = SafeMIMEText(message)
|
msg = SafeMIMEText(message)
|
||||||
msg['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
msg['From'] = from_email
|
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):
|
def mail_admins(subject, message, fail_silently=False):
|
||||||
"Sends a message to the admins, as defined by the ADMINS setting."
|
"Sends a message to the admins, as defined by the ADMINS setting."
|
||||||
from django.conf.settings import ADMINS, SERVER_EMAIL
|
send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], fail_silently)
|
||||||
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):
|
def mail_managers(subject, message, fail_silently=False):
|
||||||
"Sends a message to the managers, as defined by the MANAGERS setting."
|
"Sends a message to the managers, as defined by the MANAGERS setting."
|
||||||
from django.conf.settings import MANAGERS, SERVER_EMAIL
|
send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], fail_silently)
|
||||||
send_mail(EMAIL_SUBJECT_PREFIX + subject, message, SERVER_EMAIL, [a[1] for a in MANAGERS], fail_silently)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user