mirror of https://github.com/django/django.git
Changed e-mail to email throughout documentation and codebase. The one exception is translation strings, which I didn't want to disrupt
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15967 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7099d465ab
commit
94af19c43f
|
@ -124,7 +124,7 @@ LANGUAGE_COOKIE_NAME = 'django_language'
|
||||||
USE_L10N = False
|
USE_L10N = False
|
||||||
|
|
||||||
# Not-necessarily-technical managers of the site. They get broken link
|
# Not-necessarily-technical managers of the site. They get broken link
|
||||||
# notifications and other various e-mails.
|
# notifications and other various emails.
|
||||||
MANAGERS = ADMINS
|
MANAGERS = ADMINS
|
||||||
|
|
||||||
# Default content type and charset to use for all HttpResponse objects, if a
|
# Default content type and charset to use for all HttpResponse objects, if a
|
||||||
|
@ -139,7 +139,7 @@ FILE_CHARSET = 'utf-8'
|
||||||
# E-mail address that error messages come from.
|
# E-mail address that error messages come from.
|
||||||
SERVER_EMAIL = 'root@localhost'
|
SERVER_EMAIL = 'root@localhost'
|
||||||
|
|
||||||
# Whether to send broken-link e-mails.
|
# Whether to send broken-link emails.
|
||||||
SEND_BROKEN_LINK_EMAILS = False
|
SEND_BROKEN_LINK_EMAILS = False
|
||||||
|
|
||||||
# Database connection info.
|
# Database connection info.
|
||||||
|
@ -165,10 +165,10 @@ DATABASE_ROUTERS = []
|
||||||
# to a module that defines an EmailBackend class.
|
# to a module that defines an EmailBackend class.
|
||||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||||
|
|
||||||
# Host for sending e-mail.
|
# Host for sending email.
|
||||||
EMAIL_HOST = 'localhost'
|
EMAIL_HOST = 'localhost'
|
||||||
|
|
||||||
# Port for sending e-mail.
|
# Port for sending email.
|
||||||
EMAIL_PORT = 25
|
EMAIL_PORT = 25
|
||||||
|
|
||||||
# Optional SMTP authentication information for EMAIL_HOST.
|
# Optional SMTP authentication information for EMAIL_HOST.
|
||||||
|
@ -207,7 +207,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
||||||
# Output to use in template system for invalid (e.g. misspelled) variables.
|
# Output to use in template system for invalid (e.g. misspelled) variables.
|
||||||
TEMPLATE_STRING_IF_INVALID = ''
|
TEMPLATE_STRING_IF_INVALID = ''
|
||||||
|
|
||||||
# Default e-mail address to use for various automated correspondence from
|
# Default email address to use for various automated correspondence from
|
||||||
# the site managers.
|
# the site managers.
|
||||||
DEFAULT_FROM_EMAIL = 'webmaster@localhost'
|
DEFAULT_FROM_EMAIL = 'webmaster@localhost'
|
||||||
|
|
||||||
|
@ -462,11 +462,11 @@ COMMENTS_BANNED_USERS_GROUP = None
|
||||||
# Set to None if you're not using it.
|
# Set to None if you're not using it.
|
||||||
COMMENTS_MODERATORS_GROUP = None
|
COMMENTS_MODERATORS_GROUP = None
|
||||||
|
|
||||||
# The group ID that designates the users whose comments should be e-mailed to MANAGERS.
|
# The group ID that designates the users whose comments should be emailed to MANAGERS.
|
||||||
# Set to None if you're not using it.
|
# Set to None if you're not using it.
|
||||||
COMMENTS_SKETCHY_USERS_GROUP = None
|
COMMENTS_SKETCHY_USERS_GROUP = None
|
||||||
|
|
||||||
# The system will e-mail MANAGERS the first COMMENTS_FIRST_FEW comments by each
|
# The system will email MANAGERS the first COMMENTS_FIRST_FEW comments by each
|
||||||
# user. Set this to 0 if you want to disable it.
|
# user. Set this to 0 if you want to disable it.
|
||||||
COMMENTS_FIRST_FEW = 0
|
COMMENTS_FIRST_FEW = 0
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ class PasswordResetForm(forms.Form):
|
||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
"""
|
"""
|
||||||
Validates that an active user exists with the given e-mail address.
|
Validates that an active user exists with the given email address.
|
||||||
"""
|
"""
|
||||||
email = self.cleaned_data["email"]
|
email = self.cleaned_data["email"]
|
||||||
self.users_cache = User.objects.filter(
|
self.users_cache = User.objects.filter(
|
||||||
|
|
|
@ -100,7 +100,7 @@ class Group(models.Model):
|
||||||
|
|
||||||
A user in a group automatically has all the permissions granted to that group. For example, if the group Site editors has the permission can_edit_home_page, any user in that group will have that permission.
|
A user in a group automatically has all the permissions granted to that group. For example, if the group Site editors has the permission can_edit_home_page, any user in that group will have that permission.
|
||||||
|
|
||||||
Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them. For example, you could create a group 'Special users', and you could write code that would do special things to those users -- such as giving them access to a members-only portion of your site, or sending them members-only e-mail messages.
|
Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them. For example, you could create a group 'Special users', and you could write code that would do special things to those users -- such as giving them access to a members-only portion of your site, or sending them members-only email messages.
|
||||||
"""
|
"""
|
||||||
name = models.CharField(_('name'), max_length=80, unique=True)
|
name = models.CharField(_('name'), max_length=80, unique=True)
|
||||||
permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True)
|
permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True)
|
||||||
|
@ -115,7 +115,7 @@ class Group(models.Model):
|
||||||
class UserManager(models.Manager):
|
class UserManager(models.Manager):
|
||||||
def create_user(self, username, email, password=None):
|
def create_user(self, username, email, password=None):
|
||||||
"""
|
"""
|
||||||
Creates and saves a User with the given username, e-mail and password.
|
Creates and saves a User with the given username, email and password.
|
||||||
"""
|
"""
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ class User(models.Model):
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def email_user(self, subject, message, from_email=None):
|
def email_user(self, subject, message, from_email=None):
|
||||||
"Sends an e-mail to this User."
|
"Sends an email to this User."
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
send_mail(subject, message, from_email, [self.email])
|
send_mail(subject, message, from_email, [self.email])
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ class RemoteUserCustomTest(RemoteUserTest):
|
||||||
|
|
||||||
backend =\
|
backend =\
|
||||||
'django.contrib.auth.tests.remote_user.CustomRemoteUserBackend'
|
'django.contrib.auth.tests.remote_user.CustomRemoteUserBackend'
|
||||||
# REMOTE_USER strings with e-mail addresses for the custom backend to
|
# REMOTE_USER strings with email addresses for the custom backend to
|
||||||
# clean.
|
# clean.
|
||||||
known_user = 'knownuser@example.com'
|
known_user = 'knownuser@example.com'
|
||||||
known_user2 = 'knownuser2@example.com'
|
known_user2 = 'knownuser2@example.com'
|
||||||
|
|
|
@ -19,7 +19,7 @@ from django.core.mail.message import \
|
||||||
from django.core.mail.backends.smtp import EmailBackend as _SMTPConnection
|
from django.core.mail.backends.smtp import EmailBackend as _SMTPConnection
|
||||||
|
|
||||||
def get_connection(backend=None, fail_silently=False, **kwds):
|
def get_connection(backend=None, fail_silently=False, **kwds):
|
||||||
"""Load an e-mail backend and return an instance of it.
|
"""Load an email backend and return an instance of it.
|
||||||
|
|
||||||
If backend is None (default) settings.EMAIL_BACKEND is used.
|
If backend is None (default) settings.EMAIL_BACKEND is used.
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
|
||||||
auth_password=None, connection=None):
|
auth_password=None, connection=None):
|
||||||
"""
|
"""
|
||||||
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 emails sent.
|
||||||
|
|
||||||
If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
|
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.
|
If auth_user and auth_password are set, they're used to log in.
|
||||||
|
|
|
@ -32,7 +32,7 @@ class AdminEmailHandler(logging.Handler):
|
||||||
logging.Handler.__init__(self)
|
logging.Handler.__init__(self)
|
||||||
self.include_html = include_html
|
self.include_html = include_html
|
||||||
|
|
||||||
"""An exception log handler that e-mails log entries to site admins.
|
"""An exception log handler that emails log entries to site admins.
|
||||||
|
|
||||||
If the request is passed as the first argument to the log record,
|
If the request is passed as the first argument to the log record,
|
||||||
request data will be provided in the
|
request data will be provided in the
|
||||||
|
|
|
@ -44,7 +44,7 @@ the question on IRC -- visit the `#django IRC channel`_ on the Freenode IRC
|
||||||
network.
|
network.
|
||||||
|
|
||||||
You might notice we have a second mailing list, called django-developers_ --
|
You might notice we have a second mailing list, called django-developers_ --
|
||||||
but please don't e-mail support questions to this mailing list. This list is
|
but please don't email support questions to this mailing list. This list is
|
||||||
for discussion of the development of Django itself. Asking a tech support
|
for discussion of the development of Django itself. Asking a tech support
|
||||||
question there is considered quite impolite.
|
question there is considered quite impolite.
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Error reporting via e-mail
|
Error reporting via email
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
When you're running a public site you should always turn off the
|
When you're running a public site you should always turn off the
|
||||||
|
@ -9,12 +9,12 @@ revealed by the error pages.
|
||||||
However, running with :setting:`DEBUG` set to ``False`` means you'll never see
|
However, running with :setting:`DEBUG` set to ``False`` means you'll never see
|
||||||
errors generated by your site -- everyone will just see your public error pages.
|
errors generated by your site -- everyone will just see your public error pages.
|
||||||
You need to keep track of errors that occur in deployed sites, so Django can be
|
You need to keep track of errors that occur in deployed sites, so Django can be
|
||||||
configured to e-mail you details of those errors.
|
configured to email you details of those errors.
|
||||||
|
|
||||||
Server errors
|
Server errors
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
When :setting:`DEBUG` is ``False``, Django will e-mail the users listed in the
|
When :setting:`DEBUG` is ``False``, Django will email the users listed in the
|
||||||
:setting:`ADMINS` setting whenever your code raises an unhandled exception and
|
:setting:`ADMINS` setting whenever your code raises an unhandled exception and
|
||||||
results in an internal server error (HTTP status code 500). This gives the
|
results in an internal server error (HTTP status code 500). This gives the
|
||||||
administrators immediate notification of any errors. The :setting:`ADMINS` will
|
administrators immediate notification of any errors. The :setting:`ADMINS` will
|
||||||
|
@ -23,7 +23,7 @@ the HTTP request that caused the error.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
In order to send e-mail, Django requires a few settings telling it
|
In order to send email, Django requires a few settings telling it
|
||||||
how to connect to your mail server. At the very least, you'll need
|
how to connect to your mail server. At the very least, you'll need
|
||||||
to specify :setting:`EMAIL_HOST` and possibly
|
to specify :setting:`EMAIL_HOST` and possibly
|
||||||
:setting:`EMAIL_HOST_USER` and :setting:`EMAIL_HOST_PASSWORD`,
|
:setting:`EMAIL_HOST_USER` and :setting:`EMAIL_HOST_PASSWORD`,
|
||||||
|
@ -32,8 +32,8 @@ the HTTP request that caused the error.
|
||||||
documentation </ref/settings>` for a full list of email-related
|
documentation </ref/settings>` for a full list of email-related
|
||||||
settings.
|
settings.
|
||||||
|
|
||||||
By default, Django will send e-mail from root@localhost. However, some mail
|
By default, Django will send email from root@localhost. However, some mail
|
||||||
providers reject all e-mail from this address. To use a different sender
|
providers reject all email from this address. To use a different sender
|
||||||
address, modify the :setting:`SERVER_EMAIL` setting.
|
address, modify the :setting:`SERVER_EMAIL` setting.
|
||||||
|
|
||||||
To disable this behavior, just remove all entries from the :setting:`ADMINS`
|
To disable this behavior, just remove all entries from the :setting:`ADMINS`
|
||||||
|
@ -43,15 +43,15 @@ setting.
|
||||||
|
|
||||||
.. versionadded:: 1.3
|
.. versionadded:: 1.3
|
||||||
|
|
||||||
Server error e-mails are sent using the logging framework, so you can
|
Server error emails are sent using the logging framework, so you can
|
||||||
customize this behaviour by :doc:`customizing your logging configuration
|
customize this behaviour by :doc:`customizing your logging configuration
|
||||||
</topics/logging>`.
|
</topics/logging>`.
|
||||||
|
|
||||||
404 errors
|
404 errors
|
||||||
----------
|
----------
|
||||||
|
|
||||||
Django can also be configured to e-mail errors about broken links (404 "page
|
Django can also be configured to email errors about broken links (404 "page
|
||||||
not found" errors). Django sends e-mails about 404 errors when:
|
not found" errors). Django sends emails about 404 errors when:
|
||||||
|
|
||||||
* :setting:`DEBUG` is ``False``
|
* :setting:`DEBUG` is ``False``
|
||||||
|
|
||||||
|
@ -60,9 +60,9 @@ not found" errors). Django sends e-mails about 404 errors when:
|
||||||
* Your :setting:`MIDDLEWARE_CLASSES` setting includes ``CommonMiddleware``
|
* Your :setting:`MIDDLEWARE_CLASSES` setting includes ``CommonMiddleware``
|
||||||
(which it does by default).
|
(which it does by default).
|
||||||
|
|
||||||
If those conditions are met, Django will e-mail the users listed in the
|
If those conditions are met, Django will email the users listed in the
|
||||||
:setting:`MANAGERS` setting whenever your code raises a 404 and the request has
|
:setting:`MANAGERS` setting whenever your code raises a 404 and the request has
|
||||||
a referer. (It doesn't bother to e-mail for 404s that don't have a referer --
|
a referer. (It doesn't bother to email for 404s that don't have a referer --
|
||||||
those are usually just people typing in broken URLs or broken Web 'bots).
|
those are usually just people typing in broken URLs or broken Web 'bots).
|
||||||
|
|
||||||
You can tell Django to stop reporting particular 404s by tweaking the
|
You can tell Django to stop reporting particular 404s by tweaking the
|
||||||
|
|
|
@ -159,7 +159,7 @@ The development process
|
||||||
:doc:`FastCGI/SCGI/AJP <howto/deployment/fastcgi>` |
|
:doc:`FastCGI/SCGI/AJP <howto/deployment/fastcgi>` |
|
||||||
:doc:`Apache authentication <howto/apache-auth>` |
|
:doc:`Apache authentication <howto/apache-auth>` |
|
||||||
:doc:`Handling static files <howto/static-files>` |
|
:doc:`Handling static files <howto/static-files>` |
|
||||||
:doc:`Tracking code errors by e-mail <howto/error-reporting>`
|
:doc:`Tracking code errors by email <howto/error-reporting>`
|
||||||
|
|
||||||
Other batteries included
|
Other batteries included
|
||||||
========================
|
========================
|
||||||
|
|
|
@ -151,7 +151,7 @@ Joseph Kocherhans
|
||||||
`Gary Wilson`_
|
`Gary Wilson`_
|
||||||
Gary starting contributing patches to Django in 2006 while developing Web
|
Gary starting contributing patches to Django in 2006 while developing Web
|
||||||
applications for `The University of Texas`_ (UT). Since, he has made
|
applications for `The University of Texas`_ (UT). Since, he has made
|
||||||
contributions to the e-mail and forms systems, as well as many other
|
contributions to the email and forms systems, as well as many other
|
||||||
improvements and code cleanups throughout the code base.
|
improvements and code cleanups throughout the code base.
|
||||||
|
|
||||||
Gary is currently a developer and software engineering graduate student at
|
Gary is currently a developer and software engineering graduate student at
|
||||||
|
|
|
@ -113,7 +113,7 @@ following actions:
|
||||||
security problems immediately.
|
security problems immediately.
|
||||||
|
|
||||||
* Pre-notify everyone we know to be running the affected version(s) of
|
* Pre-notify everyone we know to be running the affected version(s) of
|
||||||
Django. We will send these notifications through private e-mail
|
Django. We will send these notifications through private email
|
||||||
which will include documentation of the vulnerability, links to the
|
which will include documentation of the vulnerability, links to the
|
||||||
relevant patch(es), and a request to keep the vulnerability
|
relevant patch(es), and a request to keep the vulnerability
|
||||||
confidential until the official go-public date.
|
confidential until the official go-public date.
|
||||||
|
@ -788,7 +788,7 @@ documentation:
|
||||||
* **Django** -- when referring to the framework, capitalize Django. It is
|
* **Django** -- when referring to the framework, capitalize Django. It is
|
||||||
lowercase only in Python code and in the djangoproject.com logo.
|
lowercase only in Python code and in the djangoproject.com logo.
|
||||||
|
|
||||||
* **e-mail** -- it has a hyphen.
|
* **email** -- no hyphen.
|
||||||
|
|
||||||
* **MySQL**
|
* **MySQL**
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ of 1.0. This includes these APIs:
|
||||||
- :doc:`Model definition, managers, querying and transactions
|
- :doc:`Model definition, managers, querying and transactions
|
||||||
</topics/db/index>`
|
</topics/db/index>`
|
||||||
|
|
||||||
- :doc:`Sending e-mail </topics/email>`.
|
- :doc:`Sending email </topics/email>`.
|
||||||
|
|
||||||
- :doc:`File handling and storage </topics/files>`
|
- :doc:`File handling and storage </topics/files>`
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ Here's the basic workflow for how a user would use a wizard:
|
||||||
3. Step 1 and 2 repeat, for every subsequent form in the wizard.
|
3. Step 1 and 2 repeat, for every subsequent form in the wizard.
|
||||||
4. Once the user has submitted all the forms and all the data has been
|
4. Once the user has submitted all the forms and all the data has been
|
||||||
validated, the wizard processes the data -- saving it to the database,
|
validated, the wizard processes the data -- saving it to the database,
|
||||||
sending an e-mail, or whatever the application needs to do.
|
sending an email, or whatever the application needs to do.
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
@ -67,7 +67,7 @@ convention is to put them in a file called :file:`forms.py` in your
|
||||||
application.
|
application.
|
||||||
|
|
||||||
For example, let's write a "contact form" wizard, where the first page's form
|
For example, let's write a "contact form" wizard, where the first page's form
|
||||||
collects the sender's e-mail address and subject, and the second page collects
|
collects the sender's email address and subject, and the second page collects
|
||||||
the message itself. Here's what the :file:`forms.py` might look like::
|
the message itself. Here's what the :file:`forms.py` might look like::
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
|
@ -181,9 +181,9 @@ fallback for cases where it is not installed.
|
||||||
Getting the current domain for display
|
Getting the current domain for display
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
LJWorld.com and Lawrence.com both have e-mail alert functionality, which lets
|
LJWorld.com and Lawrence.com both have email alert functionality, which lets
|
||||||
readers sign up to get notifications when news happens. It's pretty basic: A
|
readers sign up to get notifications when news happens. It's pretty basic: A
|
||||||
reader signs up on a Web form, and he immediately gets an e-mail saying,
|
reader signs up on a Web form, and he immediately gets an email saying,
|
||||||
"Thanks for your subscription."
|
"Thanks for your subscription."
|
||||||
|
|
||||||
It'd be inefficient and redundant to implement this signup-processing code
|
It'd be inefficient and redundant to implement this signup-processing code
|
||||||
|
@ -211,9 +211,9 @@ Here's an example of what the form-handling view looks like::
|
||||||
|
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
On Lawrence.com, this e-mail has the subject line "Thanks for subscribing to
|
On Lawrence.com, this email has the subject line "Thanks for subscribing to
|
||||||
lawrence.com alerts." On LJWorld.com, the e-mail has the subject "Thanks for
|
lawrence.com alerts." On LJWorld.com, the email has the subject "Thanks for
|
||||||
subscribing to LJWorld.com alerts." Same goes for the e-mail's message body.
|
subscribing to LJWorld.com alerts." Same goes for the email's message body.
|
||||||
|
|
||||||
Note that an even more flexible (but more heavyweight) way of doing this would
|
Note that an even more flexible (but more heavyweight) way of doing this would
|
||||||
be to use Django's template system. Assuming Lawrence.com and LJWorld.com have
|
be to use Django's template system. Assuming Lawrence.com and LJWorld.com have
|
||||||
|
|
|
@ -455,15 +455,15 @@ This example illustrates all possible attributes and methods for a
|
||||||
def author_email(self, obj):
|
def author_email(self, obj):
|
||||||
"""
|
"""
|
||||||
Takes the object returned by get_object() and returns the feed's
|
Takes the object returned by get_object() and returns the feed's
|
||||||
author's e-mail as a normal Python string.
|
author's email as a normal Python string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def author_email(self):
|
def author_email(self):
|
||||||
"""
|
"""
|
||||||
Returns the feed's author's e-mail as a normal Python string.
|
Returns the feed's author's email as a normal Python string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
author_email = 'test@example.com' # Hard-coded author e-mail.
|
author_email = 'test@example.com' # Hard-coded author email.
|
||||||
|
|
||||||
# AUTHOR LINK --One of the following three is optional. The framework
|
# AUTHOR LINK --One of the following three is optional. The framework
|
||||||
# looks for them in this order. In each case, the URL should include
|
# looks for them in this order. In each case, the URL should include
|
||||||
|
@ -637,15 +637,15 @@ This example illustrates all possible attributes and methods for a
|
||||||
def item_author_email(self, obj):
|
def item_author_email(self, obj):
|
||||||
"""
|
"""
|
||||||
Takes an item, as returned by items(), and returns the item's
|
Takes an item, as returned by items(), and returns the item's
|
||||||
author's e-mail as a normal Python string.
|
author's email as a normal Python string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def item_author_email(self):
|
def item_author_email(self):
|
||||||
"""
|
"""
|
||||||
Returns the author e-mail for every item in the feed.
|
Returns the author email for every item in the feed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
item_author_email = 'test@example.com' # Hard-coded author e-mail.
|
item_author_email = 'test@example.com' # Hard-coded author email.
|
||||||
|
|
||||||
# ITEM AUTHOR LINK -- One of the following three is optional. The
|
# ITEM AUTHOR LINK -- One of the following three is optional. The
|
||||||
# framework looks for them in this order. In each case, the URL should
|
# framework looks for them in this order. In each case, the URL should
|
||||||
|
|
|
@ -1086,7 +1086,7 @@ a password has been manually set for it.
|
||||||
.. django-admin-option:: --username
|
.. django-admin-option:: --username
|
||||||
.. django-admin-option:: --email
|
.. django-admin-option:: --email
|
||||||
|
|
||||||
The username and e-mail address for the new account can be supplied by
|
The username and email address for the new account can be supplied by
|
||||||
using the ``--username`` and ``--email`` arguments on the command
|
using the ``--username`` and ``--email`` arguments on the command
|
||||||
line. If either of those is not supplied, ``createsuperuser`` will prompt for
|
line. If either of those is not supplied, ``createsuperuser`` will prompt for
|
||||||
it when running interactively.
|
it when running interactively.
|
||||||
|
|
|
@ -89,11 +89,11 @@ and return a boolean designating whether the data was valid::
|
||||||
|
|
||||||
Let's try with some invalid data. In this case, ``subject`` is blank (an error,
|
Let's try with some invalid data. In this case, ``subject`` is blank (an error,
|
||||||
because all fields are required by default) and ``sender`` is not a valid
|
because all fields are required by default) and ``sender`` is not a valid
|
||||||
e-mail address::
|
email address::
|
||||||
|
|
||||||
>>> data = {'subject': '',
|
>>> data = {'subject': '',
|
||||||
... 'message': 'Hi there',
|
... 'message': 'Hi there',
|
||||||
... 'sender': 'invalid e-mail address',
|
... 'sender': 'invalid email address',
|
||||||
... 'cc_myself': True}
|
... 'cc_myself': True}
|
||||||
>>> f = ContactForm(data)
|
>>> f = ContactForm(data)
|
||||||
>>> f.is_valid()
|
>>> f.is_valid()
|
||||||
|
@ -105,7 +105,7 @@ Access the :attr:`~Form.errors` attribute to get a dictionary of error
|
||||||
messages::
|
messages::
|
||||||
|
|
||||||
>>> f.errors
|
>>> f.errors
|
||||||
{'sender': [u'Enter a valid e-mail address.'], 'subject': [u'This field is required.']}
|
{'sender': [u'Enter a valid email address.'], 'subject': [u'This field is required.']}
|
||||||
|
|
||||||
In this dictionary, the keys are the field names, and the values are lists of
|
In this dictionary, the keys are the field names, and the values are lists of
|
||||||
Unicode strings representing the error messages. The error messages are stored
|
Unicode strings representing the error messages. The error messages are stored
|
||||||
|
@ -204,7 +204,7 @@ If your data does *not* validate, your ``Form`` instance will not have a
|
||||||
|
|
||||||
>>> data = {'subject': '',
|
>>> data = {'subject': '',
|
||||||
... 'message': 'Hi there',
|
... 'message': 'Hi there',
|
||||||
... 'sender': 'invalid e-mail address',
|
... 'sender': 'invalid email address',
|
||||||
... 'cc_myself': True}
|
... 'cc_myself': True}
|
||||||
>>> f = ContactForm(data)
|
>>> f = ContactForm(data)
|
||||||
>>> f.is_valid()
|
>>> f.is_valid()
|
||||||
|
@ -531,25 +531,25 @@ method you're using::
|
||||||
|
|
||||||
>>> data = {'subject': '',
|
>>> data = {'subject': '',
|
||||||
... 'message': 'Hi there',
|
... 'message': 'Hi there',
|
||||||
... 'sender': 'invalid e-mail address',
|
... 'sender': 'invalid email address',
|
||||||
... 'cc_myself': True}
|
... 'cc_myself': True}
|
||||||
>>> f = ContactForm(data, auto_id=False)
|
>>> f = ContactForm(data, auto_id=False)
|
||||||
>>> print f.as_table()
|
>>> print f.as_table()
|
||||||
<tr><th>Subject:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="subject" maxlength="100" /></td></tr>
|
<tr><th>Subject:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="subject" maxlength="100" /></td></tr>
|
||||||
<tr><th>Message:</th><td><input type="text" name="message" value="Hi there" /></td></tr>
|
<tr><th>Message:</th><td><input type="text" name="message" value="Hi there" /></td></tr>
|
||||||
<tr><th>Sender:</th><td><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul><input type="text" name="sender" value="invalid e-mail address" /></td></tr>
|
<tr><th>Sender:</th><td><ul class="errorlist"><li>Enter a valid email address.</li></ul><input type="text" name="sender" value="invalid email address" /></td></tr>
|
||||||
<tr><th>Cc myself:</th><td><input checked="checked" type="checkbox" name="cc_myself" /></td></tr>
|
<tr><th>Cc myself:</th><td><input checked="checked" type="checkbox" name="cc_myself" /></td></tr>
|
||||||
>>> print f.as_ul()
|
>>> print f.as_ul()
|
||||||
<li><ul class="errorlist"><li>This field is required.</li></ul>Subject: <input type="text" name="subject" maxlength="100" /></li>
|
<li><ul class="errorlist"><li>This field is required.</li></ul>Subject: <input type="text" name="subject" maxlength="100" /></li>
|
||||||
<li>Message: <input type="text" name="message" value="Hi there" /></li>
|
<li>Message: <input type="text" name="message" value="Hi there" /></li>
|
||||||
<li><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul>Sender: <input type="text" name="sender" value="invalid e-mail address" /></li>
|
<li><ul class="errorlist"><li>Enter a valid email address.</li></ul>Sender: <input type="text" name="sender" value="invalid email address" /></li>
|
||||||
<li>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></li>
|
<li>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></li>
|
||||||
>>> print f.as_p()
|
>>> print f.as_p()
|
||||||
<p><ul class="errorlist"><li>This field is required.</li></ul></p>
|
<p><ul class="errorlist"><li>This field is required.</li></ul></p>
|
||||||
<p>Subject: <input type="text" name="subject" maxlength="100" /></p>
|
<p>Subject: <input type="text" name="subject" maxlength="100" /></p>
|
||||||
<p>Message: <input type="text" name="message" value="Hi there" /></p>
|
<p>Message: <input type="text" name="message" value="Hi there" /></p>
|
||||||
<p><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul></p>
|
<p><ul class="errorlist"><li>Enter a valid email address.</li></ul></p>
|
||||||
<p>Sender: <input type="text" name="sender" value="invalid e-mail address" /></p>
|
<p>Sender: <input type="text" name="sender" value="invalid email address" /></p>
|
||||||
<p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p>
|
<p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p>
|
||||||
|
|
||||||
Customizing the error list format
|
Customizing the error list format
|
||||||
|
@ -571,8 +571,8 @@ pass that in at construction time::
|
||||||
<div class="errorlist"><div class="error">This field is required.</div></div>
|
<div class="errorlist"><div class="error">This field is required.</div></div>
|
||||||
<p>Subject: <input type="text" name="subject" maxlength="100" /></p>
|
<p>Subject: <input type="text" name="subject" maxlength="100" /></p>
|
||||||
<p>Message: <input type="text" name="message" value="Hi there" /></p>
|
<p>Message: <input type="text" name="message" value="Hi there" /></p>
|
||||||
<div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div>
|
<div class="errorlist"><div class="error">Enter a valid email address.</div></div>
|
||||||
<p>Sender: <input type="text" name="sender" value="invalid e-mail address" /></p>
|
<p>Sender: <input type="text" name="sender" value="invalid email address" /></p>
|
||||||
<p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p>
|
<p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p>
|
||||||
|
|
||||||
More granular output
|
More granular output
|
||||||
|
|
|
@ -27,10 +27,10 @@ exception or returns the clean value::
|
||||||
u'foo@example.com'
|
u'foo@example.com'
|
||||||
>>> f.clean(u'foo@example.com')
|
>>> f.clean(u'foo@example.com')
|
||||||
u'foo@example.com'
|
u'foo@example.com'
|
||||||
>>> f.clean('invalid e-mail address')
|
>>> f.clean('invalid email address')
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValidationError: [u'Enter a valid e-mail address.']
|
ValidationError: [u'Enter a valid email address.']
|
||||||
|
|
||||||
Core field arguments
|
Core field arguments
|
||||||
--------------------
|
--------------------
|
||||||
|
@ -208,23 +208,23 @@ fields. We've specified ``auto_id=False`` to simplify the output::
|
||||||
>>> class HelpTextContactForm(forms.Form):
|
>>> class HelpTextContactForm(forms.Form):
|
||||||
... subject = forms.CharField(max_length=100, help_text='100 characters max.')
|
... subject = forms.CharField(max_length=100, help_text='100 characters max.')
|
||||||
... message = forms.CharField()
|
... message = forms.CharField()
|
||||||
... sender = forms.EmailField(help_text='A valid e-mail address, please.')
|
... sender = forms.EmailField(help_text='A valid email address, please.')
|
||||||
... cc_myself = forms.BooleanField(required=False)
|
... cc_myself = forms.BooleanField(required=False)
|
||||||
>>> f = HelpTextContactForm(auto_id=False)
|
>>> f = HelpTextContactForm(auto_id=False)
|
||||||
>>> print f.as_table()
|
>>> print f.as_table()
|
||||||
<tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /><br /><span class="helptext">100 characters max.</span></td></tr>
|
<tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /><br /><span class="helptext">100 characters max.</span></td></tr>
|
||||||
<tr><th>Message:</th><td><input type="text" name="message" /></td></tr>
|
<tr><th>Message:</th><td><input type="text" name="message" /></td></tr>
|
||||||
<tr><th>Sender:</th><td><input type="text" name="sender" /><br />A valid e-mail address, please.</td></tr>
|
<tr><th>Sender:</th><td><input type="text" name="sender" /><br />A valid email address, please.</td></tr>
|
||||||
<tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr>
|
<tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr>
|
||||||
>>> print f.as_ul()
|
>>> print f.as_ul()
|
||||||
<li>Subject: <input type="text" name="subject" maxlength="100" /> <span class="helptext">100 characters max.</span></li>
|
<li>Subject: <input type="text" name="subject" maxlength="100" /> <span class="helptext">100 characters max.</span></li>
|
||||||
<li>Message: <input type="text" name="message" /></li>
|
<li>Message: <input type="text" name="message" /></li>
|
||||||
<li>Sender: <input type="text" name="sender" /> A valid e-mail address, please.</li>
|
<li>Sender: <input type="text" name="sender" /> A valid email address, please.</li>
|
||||||
<li>Cc myself: <input type="checkbox" name="cc_myself" /></li>
|
<li>Cc myself: <input type="checkbox" name="cc_myself" /></li>
|
||||||
>>> print f.as_p()
|
>>> print f.as_p()
|
||||||
<p>Subject: <input type="text" name="subject" maxlength="100" /> <span class="helptext">100 characters max.</span></p>
|
<p>Subject: <input type="text" name="subject" maxlength="100" /> <span class="helptext">100 characters max.</span></p>
|
||||||
<p>Message: <input type="text" name="message" /></p>
|
<p>Message: <input type="text" name="message" /></p>
|
||||||
<p>Sender: <input type="text" name="sender" /> A valid e-mail address, please.</p>
|
<p>Sender: <input type="text" name="sender" /> A valid email address, please.</p>
|
||||||
<p>Cc myself: <input type="checkbox" name="cc_myself" /></p>
|
<p>Cc myself: <input type="checkbox" name="cc_myself" /></p>
|
||||||
|
|
||||||
``error_messages``
|
``error_messages``
|
||||||
|
@ -481,7 +481,7 @@ Takes four optional arguments:
|
||||||
* Default widget: ``TextInput``
|
* Default widget: ``TextInput``
|
||||||
* Empty value: ``''`` (an empty string)
|
* Empty value: ``''`` (an empty string)
|
||||||
* Normalizes to: A Unicode object.
|
* Normalizes to: A Unicode object.
|
||||||
* Validates that the given value is a valid e-mail address, using a
|
* Validates that the given value is a valid email address, using a
|
||||||
moderately complex regular expression.
|
moderately complex regular expression.
|
||||||
* Error message keys: ``required``, ``invalid``
|
* Error message keys: ``required``, ``invalid``
|
||||||
|
|
||||||
|
@ -490,7 +490,7 @@ If provided, these arguments ensure that the string is at most or at least the
|
||||||
given length.
|
given length.
|
||||||
|
|
||||||
.. versionchanged:: 1.2
|
.. versionchanged:: 1.2
|
||||||
The EmailField previously did not recognize e-mail addresses as valid that
|
The EmailField previously did not recognize email addresses as valid that
|
||||||
contained an IDN (Internationalized Domain Name; a domain containing
|
contained an IDN (Internationalized Domain Name; a domain containing
|
||||||
unicode characters) domain part. This has now been corrected.
|
unicode characters) domain part. This has now been corrected.
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ overridden:
|
||||||
* The Form subclass's ``clean()`` method. This method can perform
|
* The Form subclass's ``clean()`` method. This method can perform
|
||||||
any validation that requires access to multiple fields from the form at
|
any validation that requires access to multiple fields from the form at
|
||||||
once. This is where you might put in things to check that if field ``A``
|
once. This is where you might put in things to check that if field ``A``
|
||||||
is supplied, field ``B`` must contain a valid e-mail address and the
|
is supplied, field ``B`` must contain a valid email address and the
|
||||||
like. The data that this method returns is the final ``cleaned_data``
|
like. The data that this method returns is the final ``cleaned_data``
|
||||||
attribute for the form, so don't forget to return the full list of
|
attribute for the form, so don't forget to return the full list of
|
||||||
cleaned data if you override this method (by default, ``Form.clean()``
|
cleaned data if you override this method (by default, ``Form.clean()``
|
||||||
|
@ -187,12 +187,12 @@ a look at Django's ``EmailField``::
|
||||||
|
|
||||||
class EmailField(CharField):
|
class EmailField(CharField):
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
'invalid': _(u'Enter a valid e-mail address.'),
|
'invalid': _(u'Enter a valid email address.'),
|
||||||
}
|
}
|
||||||
default_validators = [validators.validate_email]
|
default_validators = [validators.validate_email]
|
||||||
|
|
||||||
As you can see, ``EmailField`` is just a ``CharField`` with customized error
|
As you can see, ``EmailField`` is just a ``CharField`` with customized error
|
||||||
message and a validator that validates e-mail addresses. This can also be done
|
message and a validator that validates email addresses. This can also be done
|
||||||
on field definition so::
|
on field definition so::
|
||||||
|
|
||||||
email = forms.EmailField()
|
email = forms.EmailField()
|
||||||
|
@ -200,14 +200,14 @@ on field definition so::
|
||||||
is equivalent to::
|
is equivalent to::
|
||||||
|
|
||||||
email = forms.CharField(validators=[validators.validate_email],
|
email = forms.CharField(validators=[validators.validate_email],
|
||||||
error_messages={'invalid': _(u'Enter a valid e-mail address.')})
|
error_messages={'invalid': _(u'Enter a valid email address.')})
|
||||||
|
|
||||||
|
|
||||||
Form field default cleaning
|
Form field default cleaning
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Let's firstly create a custom form field that validates its input is a string
|
Let's firstly create a custom form field that validates its input is a string
|
||||||
containing comma-separated e-mail addresses. The full class looks like this::
|
containing comma-separated email addresses. The full class looks like this::
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.validators import validate_email
|
from django.core.validators import validate_email
|
||||||
|
|
|
@ -469,7 +469,7 @@ The admin represents this as an ``<input type="text">`` (a single-line input).
|
||||||
|
|
||||||
.. class:: EmailField([max_length=75, **options])
|
.. class:: EmailField([max_length=75, **options])
|
||||||
|
|
||||||
A :class:`CharField` that checks that the value is a valid e-mail address.
|
A :class:`CharField` that checks that the value is a valid email address.
|
||||||
|
|
||||||
``FileField``
|
``FileField``
|
||||||
-------------
|
-------------
|
||||||
|
|
|
@ -66,13 +66,13 @@ ADMINS
|
||||||
Default: ``()`` (Empty tuple)
|
Default: ``()`` (Empty tuple)
|
||||||
|
|
||||||
A tuple that lists people who get code error notifications. When
|
A tuple that lists people who get code error notifications. When
|
||||||
``DEBUG=False`` and a view raises an exception, Django will e-mail these people
|
``DEBUG=False`` and a view raises an exception, Django will email these people
|
||||||
with the full exception information. Each member of the tuple should be a tuple
|
with the full exception information. Each member of the tuple should be a tuple
|
||||||
of (Full name, e-mail address). Example::
|
of (Full name, email address). Example::
|
||||||
|
|
||||||
(('John', 'john@example.com'), ('Mary', 'mary@example.com'))
|
(('John', 'john@example.com'), ('Mary', 'mary@example.com'))
|
||||||
|
|
||||||
Note that Django will e-mail *all* of these people whenever an error happens.
|
Note that Django will email *all* of these people whenever an error happens.
|
||||||
See :doc:`/howto/error-reporting` for more information.
|
See :doc:`/howto/error-reporting` for more information.
|
||||||
|
|
||||||
.. setting:: ALLOWED_INCLUDE_ROOTS
|
.. setting:: ALLOWED_INCLUDE_ROOTS
|
||||||
|
@ -756,7 +756,7 @@ DEFAULT_FROM_EMAIL
|
||||||
|
|
||||||
Default: ``'webmaster@localhost'``
|
Default: ``'webmaster@localhost'``
|
||||||
|
|
||||||
Default e-mail address to use for various automated correspondence from the
|
Default email address to use for various automated correspondence from the
|
||||||
site manager(s).
|
site manager(s).
|
||||||
|
|
||||||
.. setting:: DEFAULT_INDEX_TABLESPACE
|
.. setting:: DEFAULT_INDEX_TABLESPACE
|
||||||
|
@ -821,7 +821,7 @@ EMAIL_HOST
|
||||||
|
|
||||||
Default: ``'localhost'``
|
Default: ``'localhost'``
|
||||||
|
|
||||||
The host to use for sending e-mail.
|
The host to use for sending email.
|
||||||
|
|
||||||
See also ``EMAIL_PORT``.
|
See also ``EMAIL_PORT``.
|
||||||
|
|
||||||
|
@ -867,7 +867,7 @@ EMAIL_SUBJECT_PREFIX
|
||||||
|
|
||||||
Default: ``'[Django] '``
|
Default: ``'[Django] '``
|
||||||
|
|
||||||
Subject-line prefix for e-mail messages sent with ``django.core.mail.mail_admins``
|
Subject-line prefix for email messages sent with ``django.core.mail.mail_admins``
|
||||||
or ``django.core.mail.mail_managers``. You'll probably want to include the
|
or ``django.core.mail.mail_managers``. You'll probably want to include the
|
||||||
trailing space.
|
trailing space.
|
||||||
|
|
||||||
|
@ -1028,7 +1028,7 @@ IGNORABLE_404_ENDS
|
||||||
|
|
||||||
Default: ``('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')``
|
Default: ``('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')``
|
||||||
|
|
||||||
See also ``IGNORABLE_404_STARTS`` and ``Error reporting via e-mail``.
|
See also ``IGNORABLE_404_STARTS`` and ``Error reporting via email``.
|
||||||
|
|
||||||
.. setting:: IGNORABLE_404_STARTS
|
.. setting:: IGNORABLE_404_STARTS
|
||||||
|
|
||||||
|
@ -1038,7 +1038,7 @@ IGNORABLE_404_STARTS
|
||||||
Default: ``('/cgi-bin/', '/_vti_bin', '/_vti_inf')``
|
Default: ``('/cgi-bin/', '/_vti_bin', '/_vti_inf')``
|
||||||
|
|
||||||
A tuple of strings that specify beginnings of URLs that should be ignored by
|
A tuple of strings that specify beginnings of URLs that should be ignored by
|
||||||
the 404 e-mailer. See ``SEND_BROKEN_LINK_EMAILS``, ``IGNORABLE_404_ENDS`` and
|
the 404 emailer. See ``SEND_BROKEN_LINK_EMAILS``, ``IGNORABLE_404_ENDS`` and
|
||||||
the :doc:`/howto/error-reporting`.
|
the :doc:`/howto/error-reporting`.
|
||||||
|
|
||||||
.. setting:: INSTALLED_APPS
|
.. setting:: INSTALLED_APPS
|
||||||
|
@ -1433,7 +1433,7 @@ SEND_BROKEN_LINK_EMAILS
|
||||||
|
|
||||||
Default: ``False``
|
Default: ``False``
|
||||||
|
|
||||||
Whether to send an e-mail to the ``MANAGERS`` each time somebody visits a
|
Whether to send an email to the ``MANAGERS`` each time somebody visits a
|
||||||
Django-powered page that is 404ed with a non-empty referer (i.e., a broken
|
Django-powered page that is 404ed with a non-empty referer (i.e., a broken
|
||||||
link). This is only used if ``CommonMiddleware`` is installed (see
|
link). This is only used if ``CommonMiddleware`` is installed (see
|
||||||
:doc:`/topics/http/middleware`. See also ``IGNORABLE_404_STARTS``,
|
:doc:`/topics/http/middleware`. See also ``IGNORABLE_404_STARTS``,
|
||||||
|
@ -1459,7 +1459,7 @@ SERVER_EMAIL
|
||||||
|
|
||||||
Default: ``'root@localhost'``
|
Default: ``'root@localhost'``
|
||||||
|
|
||||||
The e-mail address that error messages come from, such as those sent to
|
The email address that error messages come from, such as those sent to
|
||||||
``ADMINS`` and ``MANAGERS``.
|
``ADMINS`` and ``MANAGERS``.
|
||||||
|
|
||||||
.. setting:: SESSION_COOKIE_AGE
|
.. setting:: SESSION_COOKIE_AGE
|
||||||
|
|
|
@ -61,7 +61,7 @@ passing them around at will, because ASCII is a subset of UTF-8.
|
||||||
Don't be fooled into thinking that if your :setting:`DEFAULT_CHARSET` setting is set
|
Don't be fooled into thinking that if your :setting:`DEFAULT_CHARSET` setting is set
|
||||||
to something other than ``'utf-8'`` you can use that other encoding in your
|
to something other than ``'utf-8'`` you can use that other encoding in your
|
||||||
bytestrings! :setting:`DEFAULT_CHARSET` only applies to the strings generated as
|
bytestrings! :setting:`DEFAULT_CHARSET` only applies to the strings generated as
|
||||||
the result of template rendering (and e-mail). Django will always assume UTF-8
|
the result of template rendering (and email). Django will always assume UTF-8
|
||||||
encoding for internal bytestrings. The reason for this is that the
|
encoding for internal bytestrings. The reason for this is that the
|
||||||
:setting:`DEFAULT_CHARSET` setting is not actually under your control (if you are the
|
:setting:`DEFAULT_CHARSET` setting is not actually under your control (if you are the
|
||||||
application developer). It's under the control of the person installing and
|
application developer). It's under the control of the person installing and
|
||||||
|
@ -304,16 +304,16 @@ A couple of tips to remember when writing your own template tags and filters:
|
||||||
translation objects into strings. It's easier to work solely with Unicode
|
translation objects into strings. It's easier to work solely with Unicode
|
||||||
strings at that point.
|
strings at that point.
|
||||||
|
|
||||||
E-mail
|
Email
|
||||||
======
|
======
|
||||||
|
|
||||||
Django's e-mail framework (in ``django.core.mail``) supports Unicode
|
Django's email framework (in ``django.core.mail``) supports Unicode
|
||||||
transparently. You can use Unicode data in the message bodies and any headers.
|
transparently. You can use Unicode data in the message bodies and any headers.
|
||||||
However, you're still obligated to respect the requirements of the e-mail
|
However, you're still obligated to respect the requirements of the email
|
||||||
specifications, so, for example, e-mail addresses should use only ASCII
|
specifications, so, for example, email addresses should use only ASCII
|
||||||
characters.
|
characters.
|
||||||
|
|
||||||
The following code example demonstrates that everything except e-mail addresses
|
The following code example demonstrates that everything except email addresses
|
||||||
can be non-ASCII::
|
can be non-ASCII::
|
||||||
|
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
|
|
|
@ -106,7 +106,7 @@ to, or in lieu of custom ``field.clean()`` methods.
|
||||||
.. data:: validate_email
|
.. data:: validate_email
|
||||||
|
|
||||||
A :class:`RegexValidator` instance that ensures a value looks like an
|
A :class:`RegexValidator` instance that ensures a value looks like an
|
||||||
e-mail address.
|
email address.
|
||||||
|
|
||||||
``validate_slug``
|
``validate_slug``
|
||||||
-----------------
|
-----------------
|
||||||
|
|
|
@ -202,7 +202,7 @@ deprecated, as described in the :ref:`upgrading notes <ref-csrf-upgrading-notes>
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
The ``SMTPConnection`` class has been deprecated in favor of a generic
|
The ``SMTPConnection`` class has been deprecated in favor of a generic
|
||||||
E-mail backend API. Old code that explicitly instantiated an instance
|
Email backend API. Old code that explicitly instantiated an instance
|
||||||
of an SMTPConnection::
|
of an SMTPConnection::
|
||||||
|
|
||||||
from django.core.mail import SMTPConnection
|
from django.core.mail import SMTPConnection
|
||||||
|
@ -211,7 +211,7 @@ of an SMTPConnection::
|
||||||
connection.send_messages(messages)
|
connection.send_messages(messages)
|
||||||
|
|
||||||
should now call :meth:`~django.core.mail.get_connection()` to
|
should now call :meth:`~django.core.mail.get_connection()` to
|
||||||
instantiate a generic e-mail connection::
|
instantiate a generic email connection::
|
||||||
|
|
||||||
from django.core.mail import get_connection
|
from django.core.mail import get_connection
|
||||||
connection = get_connection()
|
connection = get_connection()
|
||||||
|
@ -220,7 +220,7 @@ instantiate a generic e-mail connection::
|
||||||
|
|
||||||
Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
|
Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
|
||||||
may not return an SMTP connection. If you explicitly require an SMTP
|
may not return an SMTP connection. If you explicitly require an SMTP
|
||||||
connection with which to send e-mail, you can explicitly request an
|
connection with which to send email, you can explicitly request an
|
||||||
SMTP connection::
|
SMTP connection::
|
||||||
|
|
||||||
from django.core.mail import get_connection
|
from django.core.mail import get_connection
|
||||||
|
@ -385,23 +385,23 @@ malicious site in their browser. A related type of attack, 'login
|
||||||
CSRF', where an attacking site tricks a user's browser into logging
|
CSRF', where an attacking site tricks a user's browser into logging
|
||||||
into a site with someone else's credentials, is also covered.
|
into a site with someone else's credentials, is also covered.
|
||||||
|
|
||||||
E-mail Backends
|
Email Backends
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
You can now :ref:`configure the way that Django sends e-mail
|
You can now :ref:`configure the way that Django sends email
|
||||||
<topic-email-backends>`. Instead of using SMTP to send all e-mail, you
|
<topic-email-backends>`. Instead of using SMTP to send all email, you
|
||||||
can now choose a configurable e-mail backend to send messages. If your
|
can now choose a configurable email backend to send messages. If your
|
||||||
hosting provider uses a sandbox or some other non-SMTP technique for
|
hosting provider uses a sandbox or some other non-SMTP technique for
|
||||||
sending mail, you can now construct an e-mail backend that will allow
|
sending mail, you can now construct an email backend that will allow
|
||||||
Django's standard :doc:`mail sending methods</topics/email>` to use
|
Django's standard :doc:`mail sending methods</topics/email>` to use
|
||||||
those facilities.
|
those facilities.
|
||||||
|
|
||||||
This also makes it easier to debug mail sending - Django ships with
|
This also makes it easier to debug mail sending - Django ships with
|
||||||
backend implementations that allow you to send e-mail to a
|
backend implementations that allow you to send email to a
|
||||||
:ref:`file<topic-email-file-backend>`, to the
|
:ref:`file<topic-email-file-backend>`, to the
|
||||||
:ref:`console<topic-email-console-backend>`, or to
|
:ref:`console<topic-email-console-backend>`, or to
|
||||||
:ref:`memory<topic-email-memory-backend>` - you can even configure all
|
:ref:`memory<topic-email-memory-backend>` - you can even configure all
|
||||||
e-mail to be :ref:`thrown away<topic-email-dummy-backend>`.
|
email to be :ref:`thrown away<topic-email-dummy-backend>`.
|
||||||
|
|
||||||
Messages Framework
|
Messages Framework
|
||||||
------------------
|
------------------
|
||||||
|
|
|
@ -30,7 +30,7 @@ Django 1.2 introduces several large, important new features, including:
|
||||||
* Hooks for `object-level permissions`_, `permissions for anonymous users`_,
|
* Hooks for `object-level permissions`_, `permissions for anonymous users`_,
|
||||||
and `more flexible username requirements`_.
|
and `more flexible username requirements`_.
|
||||||
|
|
||||||
* Customization of e-mail sending via `e-mail backends`_.
|
* Customization of email sending via `email backends`_.
|
||||||
|
|
||||||
* New :ref:`"smart" if template tag <new-in-1.2-smart-if>` which supports
|
* New :ref:`"smart" if template tag <new-in-1.2-smart-if>` which supports
|
||||||
comparison operators.
|
comparison operators.
|
||||||
|
@ -184,23 +184,23 @@ The built-in :class:`~django.contrib.auth.models.User` model's
|
||||||
:attr:`~django.contrib.auth.models.User.username` field now allows a wider range
|
:attr:`~django.contrib.auth.models.User.username` field now allows a wider range
|
||||||
of characters, including ``@``, ``+``, ``.`` and ``-`` characters.
|
of characters, including ``@``, ``+``, ``.`` and ``-`` characters.
|
||||||
|
|
||||||
E-mail backends
|
Email backends
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
You can now :ref:`configure the way that Django sends e-mail
|
You can now :ref:`configure the way that Django sends email
|
||||||
<topic-email-backends>`. Instead of using SMTP to send all e-mail, you
|
<topic-email-backends>`. Instead of using SMTP to send all email, you
|
||||||
can now choose a configurable e-mail backend to send messages. If your
|
can now choose a configurable email backend to send messages. If your
|
||||||
hosting provider uses a sandbox or some other non-SMTP technique for
|
hosting provider uses a sandbox or some other non-SMTP technique for
|
||||||
sending mail, you can now construct an e-mail backend that will allow
|
sending mail, you can now construct an email backend that will allow
|
||||||
Django's standard :doc:`mail sending methods</topics/email>` to use
|
Django's standard :doc:`mail sending methods</topics/email>` to use
|
||||||
those facilities.
|
those facilities.
|
||||||
|
|
||||||
This also makes it easier to debug mail sending. Django ships with
|
This also makes it easier to debug mail sending. Django ships with
|
||||||
backend implementations that allow you to send e-mail to a
|
backend implementations that allow you to send email to a
|
||||||
:ref:`file<topic-email-file-backend>`, to the
|
:ref:`file<topic-email-file-backend>`, to the
|
||||||
:ref:`console<topic-email-console-backend>`, or to
|
:ref:`console<topic-email-console-backend>`, or to
|
||||||
:ref:`memory<topic-email-memory-backend>`. You can even configure all
|
:ref:`memory<topic-email-memory-backend>`. You can even configure all
|
||||||
e-mail to be :ref:`thrown away<topic-email-dummy-backend>`.
|
email to be :ref:`thrown away<topic-email-dummy-backend>`.
|
||||||
|
|
||||||
.. _new-in-1.2-smart-if:
|
.. _new-in-1.2-smart-if:
|
||||||
|
|
||||||
|
@ -868,7 +868,7 @@ imports are deprecated, as described in the :ref:`upgrading notes
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
The ``SMTPConnection`` class has been deprecated in favor of a generic
|
The ``SMTPConnection`` class has been deprecated in favor of a generic
|
||||||
e-mail backend API. Old code that explicitly instantiated an instance
|
email backend API. Old code that explicitly instantiated an instance
|
||||||
of an SMTPConnection::
|
of an SMTPConnection::
|
||||||
|
|
||||||
from django.core.mail import SMTPConnection
|
from django.core.mail import SMTPConnection
|
||||||
|
@ -877,7 +877,7 @@ of an SMTPConnection::
|
||||||
connection.send_messages(messages)
|
connection.send_messages(messages)
|
||||||
|
|
||||||
...should now call :meth:`~django.core.mail.get_connection()` to
|
...should now call :meth:`~django.core.mail.get_connection()` to
|
||||||
instantiate a generic e-mail connection::
|
instantiate a generic email connection::
|
||||||
|
|
||||||
from django.core.mail import get_connection
|
from django.core.mail import get_connection
|
||||||
connection = get_connection()
|
connection = get_connection()
|
||||||
|
@ -886,7 +886,7 @@ instantiate a generic e-mail connection::
|
||||||
|
|
||||||
Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
|
Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
|
||||||
may not return an SMTP connection. If you explicitly require an SMTP
|
may not return an SMTP connection. If you explicitly require an SMTP
|
||||||
connection with which to send e-mail, you can explicitly request an
|
connection with which to send email, you can explicitly request an
|
||||||
SMTP connection::
|
SMTP connection::
|
||||||
|
|
||||||
from django.core.mail import get_connection
|
from django.core.mail import get_connection
|
||||||
|
|
|
@ -84,7 +84,7 @@ Fields
|
||||||
|
|
||||||
.. attribute:: models.User.email
|
.. attribute:: models.User.email
|
||||||
|
|
||||||
Optional. E-mail address.
|
Optional. Email address.
|
||||||
|
|
||||||
.. attribute:: models.User.password
|
.. attribute:: models.User.password
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ Methods
|
||||||
|
|
||||||
.. method:: models.User.email_user(subject, message, from_email=None)
|
.. method:: models.User.email_user(subject, message, from_email=None)
|
||||||
|
|
||||||
Sends an e-mail to the user. If
|
Sends an email to the user. If
|
||||||
:attr:`~django.contrib.auth.models.User.from_email` is ``None``, Django
|
:attr:`~django.contrib.auth.models.User.from_email` is ``None``, Django
|
||||||
uses the :setting:`DEFAULT_FROM_EMAIL`.
|
uses the :setting:`DEFAULT_FROM_EMAIL`.
|
||||||
|
|
||||||
|
@ -948,7 +948,7 @@ includes a few other useful built-in views located in
|
||||||
|
|
||||||
Allows a user to reset their password by generating a one-time use link
|
Allows a user to reset their password by generating a one-time use link
|
||||||
that can be used to reset the password, and sending that link to the
|
that can be used to reset the password, and sending that link to the
|
||||||
user's registered e-mail address.
|
user's registered email address.
|
||||||
|
|
||||||
.. versionchanged:: 1.3
|
.. versionchanged:: 1.3
|
||||||
The ``from_email`` argument was added.
|
The ``from_email`` argument was added.
|
||||||
|
@ -960,7 +960,7 @@ includes a few other useful built-in views located in
|
||||||
:file:`registration/password_reset_form.html` if not supplied.
|
:file:`registration/password_reset_form.html` if not supplied.
|
||||||
|
|
||||||
* ``email_template_name``: The full name of a template to use for
|
* ``email_template_name``: The full name of a template to use for
|
||||||
generating the e-mail with the new password. This will default to
|
generating the email with the new password. This will default to
|
||||||
:file:`registration/password_reset_email.html` if not supplied.
|
:file:`registration/password_reset_email.html` if not supplied.
|
||||||
|
|
||||||
* ``password_reset_form``: Form that will be used to set the password.
|
* ``password_reset_form``: Form that will be used to set the password.
|
||||||
|
@ -973,7 +973,7 @@ includes a few other useful built-in views located in
|
||||||
* ``post_reset_redirect``: The URL to redirect to after a successful
|
* ``post_reset_redirect``: The URL to redirect to after a successful
|
||||||
password change.
|
password change.
|
||||||
|
|
||||||
* ``from_email``: A valid e-mail address. By default Django uses
|
* ``from_email``: A valid email address. By default Django uses
|
||||||
the :setting:`DEFAULT_FROM_EMAIL`.
|
the :setting:`DEFAULT_FROM_EMAIL`.
|
||||||
|
|
||||||
**Template context:**
|
**Template context:**
|
||||||
|
@ -1061,7 +1061,7 @@ provides several built-in forms located in :mod:`django.contrib.auth.forms`:
|
||||||
|
|
||||||
.. class:: PasswordResetForm
|
.. class:: PasswordResetForm
|
||||||
|
|
||||||
A form for generating and e-mailing a one-time use link to reset a
|
A form for generating and emailing a one-time use link to reset a
|
||||||
user's password.
|
user's password.
|
||||||
|
|
||||||
.. class:: SetPasswordForm
|
.. class:: SetPasswordForm
|
||||||
|
@ -1384,7 +1384,7 @@ example, if the group ``Site editors`` has the permission
|
||||||
Beyond permissions, groups are a convenient way to categorize users to give
|
Beyond permissions, groups are a convenient way to categorize users to give
|
||||||
them some label, or extended functionality. For example, you could create a
|
them some label, or extended functionality. For example, you could create a
|
||||||
group ``'Special users'``, and you could write code that could, say, give them
|
group ``'Special users'``, and you could write code that could, say, give them
|
||||||
access to a members-only portion of your site, or send them members-only e-mail
|
access to a members-only portion of your site, or send them members-only email
|
||||||
messages.
|
messages.
|
||||||
|
|
||||||
Messages
|
Messages
|
||||||
|
|
|
@ -941,7 +941,7 @@ Many Web pages' contents differ based on authentication and a host of other
|
||||||
variables, and cache systems that blindly save pages based purely on URLs could
|
variables, and cache systems that blindly save pages based purely on URLs could
|
||||||
expose incorrect or sensitive data to subsequent visitors to those pages.
|
expose incorrect or sensitive data to subsequent visitors to those pages.
|
||||||
|
|
||||||
For example, say you operate a Web e-mail system, and the contents of the
|
For example, say you operate a Web email system, and the contents of the
|
||||||
"inbox" page obviously depend on which user is logged in. If an ISP blindly
|
"inbox" page obviously depend on which user is logged in. If an ISP blindly
|
||||||
cached your site, then the first user who logged in through that ISP would have
|
cached your site, then the first user who logged in through that ISP would have
|
||||||
his user-specific inbox page cached for subsequent visitors to the site. That's
|
his user-specific inbox page cached for subsequent visitors to the site. That's
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
==============
|
==============
|
||||||
Sending e-mail
|
Sending email
|
||||||
==============
|
==============
|
||||||
|
|
||||||
.. module:: django.core.mail
|
.. module:: django.core.mail
|
||||||
:synopsis: Helpers to easily send e-mail.
|
:synopsis: Helpers to easily send email.
|
||||||
|
|
||||||
Although Python makes sending e-mail relatively easy via the `smtplib
|
Although Python makes sending email relatively easy via the `smtplib
|
||||||
library`_, Django provides a couple of light wrappers over it. These wrappers
|
library`_, Django provides a couple of light wrappers over it. These wrappers
|
||||||
are provided to make sending e-mail extra quick, to make it easy to test
|
are provided to make sending email extra quick, to make it easy to test
|
||||||
e-mail sending during development, and to provide support for platforms that
|
email sending during development, and to provide support for platforms that
|
||||||
can't use SMTP.
|
can't use SMTP.
|
||||||
|
|
||||||
The code lives in the ``django.core.mail`` module.
|
The code lives in the ``django.core.mail`` module.
|
||||||
|
@ -33,7 +33,7 @@ set, are used to authenticate to the SMTP server, and the
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
The character set of e-mail sent with ``django.core.mail`` will be set to
|
The character set of email sent with ``django.core.mail`` will be set to
|
||||||
the value of your :setting:`DEFAULT_CHARSET` setting.
|
the value of your :setting:`DEFAULT_CHARSET` setting.
|
||||||
|
|
||||||
send_mail()
|
send_mail()
|
||||||
|
@ -41,7 +41,7 @@ send_mail()
|
||||||
|
|
||||||
.. function:: send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None)
|
.. function:: send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None)
|
||||||
|
|
||||||
The simplest way to send e-mail is using
|
The simplest way to send email is using
|
||||||
``django.core.mail.send_mail()``.
|
``django.core.mail.send_mail()``.
|
||||||
|
|
||||||
The ``subject``, ``message``, ``from_email`` and ``recipient_list`` parameters
|
The ``subject``, ``message``, ``from_email`` and ``recipient_list`` parameters
|
||||||
|
@ -50,9 +50,9 @@ are required.
|
||||||
* ``subject``: A string.
|
* ``subject``: A string.
|
||||||
* ``message``: A string.
|
* ``message``: A string.
|
||||||
* ``from_email``: A string.
|
* ``from_email``: A string.
|
||||||
* ``recipient_list``: A list of strings, each an e-mail address. Each
|
* ``recipient_list``: A list of strings, each an email address. Each
|
||||||
member of ``recipient_list`` will see the other recipients in the "To:"
|
member of ``recipient_list`` will see the other recipients in the "To:"
|
||||||
field of the e-mail message.
|
field of the email message.
|
||||||
* ``fail_silently``: A boolean. If it's ``False``, ``send_mail`` will raise
|
* ``fail_silently``: A boolean. If it's ``False``, ``send_mail`` will raise
|
||||||
an ``smtplib.SMTPException``. See the `smtplib docs`_ for a list of
|
an ``smtplib.SMTPException``. See the `smtplib docs`_ for a list of
|
||||||
possible exceptions, all of which are subclasses of ``SMTPException``.
|
possible exceptions, all of which are subclasses of ``SMTPException``.
|
||||||
|
@ -62,9 +62,9 @@ are required.
|
||||||
* ``auth_password``: The optional password to use to authenticate to the
|
* ``auth_password``: The optional password to use to authenticate to the
|
||||||
SMTP server. If this isn't provided, Django will use the value of the
|
SMTP server. If this isn't provided, Django will use the value of the
|
||||||
:setting:`EMAIL_HOST_PASSWORD` setting.
|
:setting:`EMAIL_HOST_PASSWORD` setting.
|
||||||
* ``connection``: The optional e-mail backend to use to send the mail.
|
* ``connection``: The optional email backend to use to send the mail.
|
||||||
If unspecified, an instance of the default backend will be used.
|
If unspecified, an instance of the default backend will be used.
|
||||||
See the documentation on :ref:`E-mail backends <topic-email-backends>`
|
See the documentation on :ref:`Email backends <topic-email-backends>`
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
.. _smtplib docs: http://docs.python.org/library/smtplib.html
|
.. _smtplib docs: http://docs.python.org/library/smtplib.html
|
||||||
|
@ -74,7 +74,7 @@ send_mass_mail()
|
||||||
|
|
||||||
.. function:: send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None, connection=None)
|
.. function:: send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None, connection=None)
|
||||||
|
|
||||||
``django.core.mail.send_mass_mail()`` is intended to handle mass e-mailing.
|
``django.core.mail.send_mass_mail()`` is intended to handle mass emailing.
|
||||||
|
|
||||||
``datatuple`` is a tuple in which each element is in this format::
|
``datatuple`` is a tuple in which each element is in this format::
|
||||||
|
|
||||||
|
@ -83,9 +83,9 @@ send_mass_mail()
|
||||||
``fail_silently``, ``auth_user`` and ``auth_password`` have the same functions
|
``fail_silently``, ``auth_user`` and ``auth_password`` have the same functions
|
||||||
as in :meth:`~django.core.mail.send_mail()`.
|
as in :meth:`~django.core.mail.send_mail()`.
|
||||||
|
|
||||||
Each separate element of ``datatuple`` results in a separate e-mail message.
|
Each separate element of ``datatuple`` results in a separate email message.
|
||||||
As in :meth:`~django.core.mail.send_mail()`, recipients in the same
|
As in :meth:`~django.core.mail.send_mail()`, recipients in the same
|
||||||
``recipient_list`` will all see the other addresses in the e-mail messages'
|
``recipient_list`` will all see the other addresses in the email messages'
|
||||||
"To:" field.
|
"To:" field.
|
||||||
|
|
||||||
For example, the following code would send two different messages to
|
For example, the following code would send two different messages to
|
||||||
|
@ -111,21 +111,21 @@ mail_admins()
|
||||||
|
|
||||||
.. function:: mail_admins(subject, message, fail_silently=False, connection=None, html_message=None)
|
.. function:: mail_admins(subject, message, fail_silently=False, connection=None, html_message=None)
|
||||||
|
|
||||||
``django.core.mail.mail_admins()`` is a shortcut for sending an e-mail to the
|
``django.core.mail.mail_admins()`` is a shortcut for sending an email to the
|
||||||
site admins, as defined in the :setting:`ADMINS` setting.
|
site admins, as defined in the :setting:`ADMINS` setting.
|
||||||
|
|
||||||
``mail_admins()`` prefixes the subject with the value of the
|
``mail_admins()`` prefixes the subject with the value of the
|
||||||
:setting:`EMAIL_SUBJECT_PREFIX` setting, which is ``"[Django] "`` by default.
|
:setting:`EMAIL_SUBJECT_PREFIX` setting, which is ``"[Django] "`` by default.
|
||||||
|
|
||||||
The "From:" header of the e-mail will be the value of the
|
The "From:" header of the email will be the value of the
|
||||||
:setting:`SERVER_EMAIL` setting.
|
:setting:`SERVER_EMAIL` setting.
|
||||||
|
|
||||||
This method exists for convenience and readability.
|
This method exists for convenience and readability.
|
||||||
|
|
||||||
.. versionchanged:: 1.3
|
.. versionchanged:: 1.3
|
||||||
|
|
||||||
If ``html_message`` is provided, the resulting e-mail will be a
|
If ``html_message`` is provided, the resulting email will be a
|
||||||
multipart/alternative e-mail with ``message`` as the "text/plain"
|
multipart/alternative email with ``message`` as the "text/plain"
|
||||||
content type and ``html_message`` as the "text/html" content type.
|
content type and ``html_message`` as the "text/html" content type.
|
||||||
|
|
||||||
mail_managers()
|
mail_managers()
|
||||||
|
@ -134,20 +134,20 @@ mail_managers()
|
||||||
.. function:: mail_managers(subject, message, fail_silently=False, connection=None, html_message=None)
|
.. function:: mail_managers(subject, message, fail_silently=False, connection=None, html_message=None)
|
||||||
|
|
||||||
``django.core.mail.mail_managers()`` is just like ``mail_admins()``, except it
|
``django.core.mail.mail_managers()`` is just like ``mail_admins()``, except it
|
||||||
sends an e-mail to the site managers, as defined in the :setting:`MANAGERS`
|
sends an email to the site managers, as defined in the :setting:`MANAGERS`
|
||||||
setting.
|
setting.
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
========
|
========
|
||||||
|
|
||||||
This sends a single e-mail to john@example.com and jane@example.com, with them
|
This sends a single email to john@example.com and jane@example.com, with them
|
||||||
both appearing in the "To:"::
|
both appearing in the "To:"::
|
||||||
|
|
||||||
send_mail('Subject', 'Message.', 'from@example.com',
|
send_mail('Subject', 'Message.', 'from@example.com',
|
||||||
['john@example.com', 'jane@example.com'])
|
['john@example.com', 'jane@example.com'])
|
||||||
|
|
||||||
This sends a message to john@example.com and jane@example.com, with them both
|
This sends a message to john@example.com and jane@example.com, with them both
|
||||||
receiving a separate e-mail::
|
receiving a separate email::
|
||||||
|
|
||||||
datatuple = (
|
datatuple = (
|
||||||
('Subject', 'Message.', 'from@example.com', ['john@example.com']),
|
('Subject', 'Message.', 'from@example.com', ['john@example.com']),
|
||||||
|
@ -159,19 +159,19 @@ Preventing header injection
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
`Header injection`_ is a security exploit in which an attacker inserts extra
|
`Header injection`_ is a security exploit in which an attacker inserts extra
|
||||||
e-mail headers to control the "To:" and "From:" in e-mail messages that your
|
email headers to control the "To:" and "From:" in email messages that your
|
||||||
scripts generate.
|
scripts generate.
|
||||||
|
|
||||||
The Django e-mail functions outlined above all protect against header injection
|
The Django email functions outlined above all protect against header injection
|
||||||
by forbidding newlines in header values. If any ``subject``, ``from_email`` or
|
by forbidding newlines in header values. If any ``subject``, ``from_email`` or
|
||||||
``recipient_list`` contains a newline (in either Unix, Windows or Mac style),
|
``recipient_list`` contains a newline (in either Unix, Windows or Mac style),
|
||||||
the e-mail function (e.g. :meth:`~django.core.mail.send_mail()`) will raise
|
the email function (e.g. :meth:`~django.core.mail.send_mail()`) will raise
|
||||||
``django.core.mail.BadHeaderError`` (a subclass of ``ValueError``) and, hence,
|
``django.core.mail.BadHeaderError`` (a subclass of ``ValueError``) and, hence,
|
||||||
will not send the e-mail. It's your responsibility to validate all data before
|
will not send the email. It's your responsibility to validate all data before
|
||||||
passing it to the e-mail functions.
|
passing it to the email functions.
|
||||||
|
|
||||||
If a ``message`` contains headers at the start of the string, the headers will
|
If a ``message`` contains headers at the start of the string, the headers will
|
||||||
simply be printed as the first bit of the e-mail message.
|
simply be printed as the first bit of the email message.
|
||||||
|
|
||||||
Here's an example view that takes a ``subject``, ``message`` and ``from_email``
|
Here's an example view that takes a ``subject``, ``message`` and ``from_email``
|
||||||
from the request's POST data, sends that to admin@example.com and redirects to
|
from the request's POST data, sends that to admin@example.com and redirects to
|
||||||
|
@ -208,24 +208,24 @@ wrappers that make use of the :class:`~django.core.mail.EmailMessage` class.
|
||||||
Not all features of the :class:`~django.core.mail.EmailMessage` class are
|
Not all features of the :class:`~django.core.mail.EmailMessage` class are
|
||||||
available through the :meth:`~django.core.mail.send_mail()` and related
|
available through the :meth:`~django.core.mail.send_mail()` and related
|
||||||
wrapper functions. If you wish to use advanced features, such as BCC'ed
|
wrapper functions. If you wish to use advanced features, such as BCC'ed
|
||||||
recipients, file attachments, or multi-part e-mail, you'll need to create
|
recipients, file attachments, or multi-part email, you'll need to create
|
||||||
:class:`~django.core.mail.EmailMessage` instances directly.
|
:class:`~django.core.mail.EmailMessage` instances directly.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
This is a design feature. :meth:`~django.core.mail.send_mail()` and
|
This is a design feature. :meth:`~django.core.mail.send_mail()` and
|
||||||
related functions were originally the only interface Django provided.
|
related functions were originally the only interface Django provided.
|
||||||
However, the list of parameters they accepted was slowly growing over
|
However, the list of parameters they accepted was slowly growing over
|
||||||
time. It made sense to move to a more object-oriented design for e-mail
|
time. It made sense to move to a more object-oriented design for email
|
||||||
messages and retain the original functions only for backwards
|
messages and retain the original functions only for backwards
|
||||||
compatibility.
|
compatibility.
|
||||||
|
|
||||||
:class:`~django.core.mail.EmailMessage` is responsible for creating the e-mail
|
:class:`~django.core.mail.EmailMessage` is responsible for creating the email
|
||||||
message itself. The :ref:`e-mail backend <topic-email-backends>` is then
|
message itself. The :ref:`email backend <topic-email-backends>` is then
|
||||||
responsible for sending the e-mail.
|
responsible for sending the email.
|
||||||
|
|
||||||
For convenience, :class:`~django.core.mail.EmailMessage` provides a simple
|
For convenience, :class:`~django.core.mail.EmailMessage` provides a simple
|
||||||
``send()`` method for sending a single e-mail. If you need to send multiple
|
``send()`` method for sending a single email. If you need to send multiple
|
||||||
messages, the e-mail backend API :ref:`provides an alternative
|
messages, the email backend API :ref:`provides an alternative
|
||||||
<topics-sending-multiple-emails>`.
|
<topics-sending-multiple-emails>`.
|
||||||
|
|
||||||
EmailMessage Objects
|
EmailMessage Objects
|
||||||
|
@ -241,7 +241,7 @@ All parameters are optional and can be set at any time prior to calling the
|
||||||
.. versionchanged:: 1.3
|
.. versionchanged:: 1.3
|
||||||
The ``cc`` argument was added.
|
The ``cc`` argument was added.
|
||||||
|
|
||||||
* ``subject``: The subject line of the e-mail.
|
* ``subject``: The subject line of the email.
|
||||||
|
|
||||||
* ``body``: The body text. This should be a plain text message.
|
* ``body``: The body text. This should be a plain text message.
|
||||||
|
|
||||||
|
@ -252,9 +252,9 @@ All parameters are optional and can be set at any time prior to calling the
|
||||||
* ``to``: A list or tuple of recipient addresses.
|
* ``to``: A list or tuple of recipient addresses.
|
||||||
|
|
||||||
* ``bcc``: A list or tuple of addresses used in the "Bcc" header when
|
* ``bcc``: A list or tuple of addresses used in the "Bcc" header when
|
||||||
sending the e-mail.
|
sending the email.
|
||||||
|
|
||||||
* ``connection``: An e-mail backend instance. Use this parameter if
|
* ``connection``: An email backend instance. Use this parameter if
|
||||||
you want to use the same connection for multiple messages. If omitted, a
|
you want to use the same connection for multiple messages. If omitted, a
|
||||||
new connection is created when ``send()`` is called.
|
new connection is created when ``send()`` is called.
|
||||||
|
|
||||||
|
@ -265,10 +265,10 @@ All parameters are optional and can be set at any time prior to calling the
|
||||||
* ``headers``: A dictionary of extra headers to put on the message. The
|
* ``headers``: A dictionary of extra headers to put on the message. The
|
||||||
keys are the header name, values are the header values. It's up to the
|
keys are the header name, values are the header values. It's up to the
|
||||||
caller to ensure header names and values are in the correct format for
|
caller to ensure header names and values are in the correct format for
|
||||||
an e-mail message.
|
an email message.
|
||||||
|
|
||||||
* ``cc``: A list or tuple of recipient addresses used in the "Cc" header
|
* ``cc``: A list or tuple of recipient addresses used in the "Cc" header
|
||||||
when sending the e-mail.
|
when sending the email.
|
||||||
|
|
||||||
For example::
|
For example::
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ For example::
|
||||||
The class has the following methods:
|
The class has the following methods:
|
||||||
|
|
||||||
* ``send(fail_silently=False)`` sends the message. If a connection was
|
* ``send(fail_silently=False)`` sends the message. If a connection was
|
||||||
specified when the e-mail was constructed, that connection will be used.
|
specified when the email was constructed, that connection will be used.
|
||||||
Otherwise, an instance of the default backend will be instantiated and
|
Otherwise, an instance of the default backend will be instantiated and
|
||||||
used. If the keyword argument ``fail_silently`` is ``True``, exceptions
|
used. If the keyword argument ``fail_silently`` is ``True``, exceptions
|
||||||
raised while sending the message will be quashed.
|
raised while sending the message will be quashed.
|
||||||
|
@ -307,7 +307,7 @@ The class has the following methods:
|
||||||
|
|
||||||
* Alternatively, you can pass ``attach()`` three arguments:
|
* Alternatively, you can pass ``attach()`` three arguments:
|
||||||
``filename``, ``content`` and ``mimetype``. ``filename`` is the name
|
``filename``, ``content`` and ``mimetype``. ``filename`` is the name
|
||||||
of the file attachment as it will appear in the e-mail, ``content`` is
|
of the file attachment as it will appear in the email, ``content`` is
|
||||||
the data that will be contained inside the attachment and
|
the data that will be contained inside the attachment and
|
||||||
``mimetype`` is the optional MIME type for the attachment. If you
|
``mimetype`` is the optional MIME type for the attachment. If you
|
||||||
omit ``mimetype``, the MIME content type will be guessed from the
|
omit ``mimetype``, the MIME content type will be guessed from the
|
||||||
|
@ -329,12 +329,12 @@ The class has the following methods:
|
||||||
Sending alternative content types
|
Sending alternative content types
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
It can be useful to include multiple versions of the content in an e-mail; the
|
It can be useful to include multiple versions of the content in an email; the
|
||||||
classic example is to send both text and HTML versions of a message. With
|
classic example is to send both text and HTML versions of a message. With
|
||||||
Django's e-mail library, you can do this using the ``EmailMultiAlternatives``
|
Django's email library, you can do this using the ``EmailMultiAlternatives``
|
||||||
class. This subclass of :class:`~django.core.mail.EmailMessage` has an
|
class. This subclass of :class:`~django.core.mail.EmailMessage` has an
|
||||||
``attach_alternative()`` method for including extra versions of the message
|
``attach_alternative()`` method for including extra versions of the message
|
||||||
body in the e-mail. All the other methods (including the class initialization)
|
body in the email. All the other methods (including the class initialization)
|
||||||
are inherited directly from :class:`~django.core.mail.EmailMessage`.
|
are inherited directly from :class:`~django.core.mail.EmailMessage`.
|
||||||
|
|
||||||
To send a text and HTML combination, you could write::
|
To send a text and HTML combination, you could write::
|
||||||
|
@ -351,7 +351,7 @@ To send a text and HTML combination, you could write::
|
||||||
By default, the MIME type of the ``body`` parameter in an
|
By default, the MIME type of the ``body`` parameter in an
|
||||||
:class:`~django.core.mail.EmailMessage` is ``"text/plain"``. It is good
|
:class:`~django.core.mail.EmailMessage` is ``"text/plain"``. It is good
|
||||||
practice to leave this alone, because it guarantees that any recipient will be
|
practice to leave this alone, because it guarantees that any recipient will be
|
||||||
able to read the e-mail, regardless of their mail client. However, if you are
|
able to read the email, regardless of their mail client. However, if you are
|
||||||
confident that your recipients can handle an alternative content type, you can
|
confident that your recipients can handle an alternative content type, you can
|
||||||
use the ``content_subtype`` attribute on the
|
use the ``content_subtype`` attribute on the
|
||||||
:class:`~django.core.mail.EmailMessage` class to change the main content type.
|
:class:`~django.core.mail.EmailMessage` class to change the main content type.
|
||||||
|
@ -369,13 +369,13 @@ E-Mail Backends
|
||||||
|
|
||||||
.. versionadded:: 1.2
|
.. versionadded:: 1.2
|
||||||
|
|
||||||
The actual sending of an e-mail is handled by the e-mail backend.
|
The actual sending of an email is handled by the email backend.
|
||||||
|
|
||||||
The e-mail backend class has the following methods:
|
The email backend class has the following methods:
|
||||||
|
|
||||||
* ``open()`` instantiates an long-lived e-mail-sending connection.
|
* ``open()`` instantiates an long-lived email-sending connection.
|
||||||
|
|
||||||
* ``close()`` closes the current e-mail-sending connection.
|
* ``close()`` closes the current email-sending connection.
|
||||||
|
|
||||||
* ``send_messages(email_messages)`` sends a list of
|
* ``send_messages(email_messages)`` sends a list of
|
||||||
:class:`~django.core.mail.EmailMessage` objects. If the connection is
|
:class:`~django.core.mail.EmailMessage` objects. If the connection is
|
||||||
|
@ -383,38 +383,38 @@ The e-mail backend class has the following methods:
|
||||||
connection afterwards. If the connection is already open, it will be
|
connection afterwards. If the connection is already open, it will be
|
||||||
left open after mail has been sent.
|
left open after mail has been sent.
|
||||||
|
|
||||||
Obtaining an instance of an e-mail backend
|
Obtaining an instance of an email backend
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
|
||||||
The :meth:`get_connection` function in ``django.core.mail`` returns an
|
The :meth:`get_connection` function in ``django.core.mail`` returns an
|
||||||
instance of the e-mail backend that you can use.
|
instance of the email backend that you can use.
|
||||||
|
|
||||||
.. currentmodule:: django.core.mail
|
.. currentmodule:: django.core.mail
|
||||||
|
|
||||||
.. function:: get_connection(backend=None, fail_silently=False, *args, **kwargs)
|
.. function:: get_connection(backend=None, fail_silently=False, *args, **kwargs)
|
||||||
|
|
||||||
By default, a call to ``get_connection()`` will return an instance of the
|
By default, a call to ``get_connection()`` will return an instance of the
|
||||||
e-mail backend specified in :setting:`EMAIL_BACKEND`. If you specify the
|
email backend specified in :setting:`EMAIL_BACKEND`. If you specify the
|
||||||
``backend`` argument, an instance of that backend will be instantiated.
|
``backend`` argument, an instance of that backend will be instantiated.
|
||||||
|
|
||||||
The ``fail_silently`` argument controls how the backend should handle errors.
|
The ``fail_silently`` argument controls how the backend should handle errors.
|
||||||
If ``fail_silently`` is True, exceptions during the e-mail sending process
|
If ``fail_silently`` is True, exceptions during the email sending process
|
||||||
will be silently ignored.
|
will be silently ignored.
|
||||||
|
|
||||||
All other arguments are passed directly to the constructor of the
|
All other arguments are passed directly to the constructor of the
|
||||||
e-mail backend.
|
email backend.
|
||||||
|
|
||||||
Django ships with several e-mail sending backends. With the exception of the
|
Django ships with several email sending backends. With the exception of the
|
||||||
SMTP backend (which is the default), these backends are only useful during
|
SMTP backend (which is the default), these backends are only useful during
|
||||||
testing and development. If you have special e-mail sending requirements, you
|
testing and development. If you have special email sending requirements, you
|
||||||
can :ref:`write your own e-mail backend <topic-custom-email-backend>`.
|
can :ref:`write your own email backend <topic-custom-email-backend>`.
|
||||||
|
|
||||||
.. _topic-email-smtp-backend:
|
.. _topic-email-smtp-backend:
|
||||||
|
|
||||||
SMTP backend
|
SMTP backend
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
This is the default backend. E-mail will be sent through a SMTP server.
|
This is the default backend. Email will be sent through a SMTP server.
|
||||||
The server address and authentication credentials are set in the
|
The server address and authentication credentials are set in the
|
||||||
:setting:`EMAIL_HOST`, :setting:`EMAIL_PORT`, :setting:`EMAIL_HOST_USER`,
|
:setting:`EMAIL_HOST`, :setting:`EMAIL_PORT`, :setting:`EMAIL_HOST_USER`,
|
||||||
:setting:`EMAIL_HOST_PASSWORD` and :setting:`EMAIL_USE_TLS` settings in your
|
:setting:`EMAIL_HOST_PASSWORD` and :setting:`EMAIL_USE_TLS` settings in your
|
||||||
|
@ -429,8 +429,8 @@ want to specify it explicitly, put the following in your settings::
|
||||||
|
|
||||||
Prior to version 1.2, Django provided a
|
Prior to version 1.2, Django provided a
|
||||||
:class:`~django.core.mail.SMTPConnection` class. This class provided a way
|
:class:`~django.core.mail.SMTPConnection` class. This class provided a way
|
||||||
to directly control the use of SMTP to send e-mail. This class has been
|
to directly control the use of SMTP to send email. This class has been
|
||||||
deprecated in favor of the generic e-mail backend API.
|
deprecated in favor of the generic email backend API.
|
||||||
|
|
||||||
For backwards compatibility :class:`~django.core.mail.SMTPConnection` is
|
For backwards compatibility :class:`~django.core.mail.SMTPConnection` is
|
||||||
still available in ``django.core.mail`` as an alias for the SMTP backend.
|
still available in ``django.core.mail`` as an alias for the SMTP backend.
|
||||||
|
@ -441,8 +441,8 @@ want to specify it explicitly, put the following in your settings::
|
||||||
Console backend
|
Console backend
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Instead of sending out real e-mails the console backend just writes the
|
Instead of sending out real emails the console backend just writes the
|
||||||
e-mails that would be send to the standard output. By default, the console
|
emails that would be send to the standard output. By default, the console
|
||||||
backend writes to ``stdout``. You can use a different stream-like object by
|
backend writes to ``stdout``. You can use a different stream-like object by
|
||||||
providing the ``stream`` keyword argument when constructing the connection.
|
providing the ``stream`` keyword argument when constructing the connection.
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ convenience that can be used during development.
|
||||||
File backend
|
File backend
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
The file backend writes e-mails to a file. A new file is created for each new
|
The file backend writes emails to a file. A new file is created for each new
|
||||||
session that is opened on this backend. The directory to which the files are
|
session that is opened on this backend. The directory to which the files are
|
||||||
written is either taken from the :setting:`EMAIL_FILE_PATH` setting or from
|
written is either taken from the :setting:`EMAIL_FILE_PATH` setting or from
|
||||||
the ``file_path`` keyword when creating a connection with
|
the ``file_path`` keyword when creating a connection with
|
||||||
|
@ -505,15 +505,15 @@ convenience that can be used during development.
|
||||||
|
|
||||||
.. _topic-custom-email-backend:
|
.. _topic-custom-email-backend:
|
||||||
|
|
||||||
Defining a custom e-mail backend
|
Defining a custom email backend
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
If you need to change how e-mails are sent you can write your own e-mail
|
If you need to change how emails are sent you can write your own email
|
||||||
backend. The ``EMAIL_BACKEND`` setting in your settings file is then the
|
backend. The ``EMAIL_BACKEND`` setting in your settings file is then the
|
||||||
Python import path for your backend class.
|
Python import path for your backend class.
|
||||||
|
|
||||||
Custom e-mail backends should subclass ``BaseEmailBackend`` that is located in
|
Custom email backends should subclass ``BaseEmailBackend`` that is located in
|
||||||
the ``django.core.mail.backends.base`` module. A custom e-mail backend must
|
the ``django.core.mail.backends.base`` module. A custom email backend must
|
||||||
implement the ``send_messages(email_messages)`` method. This method receives a
|
implement the ``send_messages(email_messages)`` method. This method receives a
|
||||||
list of :class:`~django.core.mail.EmailMessage` instances and returns the
|
list of :class:`~django.core.mail.EmailMessage` instances and returns the
|
||||||
number of successfully delivered messages. If your backend has any concept of
|
number of successfully delivered messages. If your backend has any concept of
|
||||||
|
@ -523,15 +523,15 @@ implementation.
|
||||||
|
|
||||||
.. _topics-sending-multiple-emails:
|
.. _topics-sending-multiple-emails:
|
||||||
|
|
||||||
Sending multiple e-mails
|
Sending multiple emails
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
Establishing and closing an SMTP connection (or any other network connection,
|
Establishing and closing an SMTP connection (or any other network connection,
|
||||||
for that matter) is an expensive process. If you have a lot of e-mails to send,
|
for that matter) is an expensive process. If you have a lot of emails to send,
|
||||||
it makes sense to reuse an SMTP connection, rather than creating and
|
it makes sense to reuse an SMTP connection, rather than creating and
|
||||||
destroying a connection every time you want to send an e-mail.
|
destroying a connection every time you want to send an email.
|
||||||
|
|
||||||
There are two ways you tell an e-mail backend to reuse a connection.
|
There are two ways you tell an email backend to reuse a connection.
|
||||||
|
|
||||||
Firstly, you can use the ``send_messages()`` method. ``send_messages()`` takes
|
Firstly, you can use the ``send_messages()`` method. ``send_messages()`` takes
|
||||||
a list of :class:`~django.core.mail.EmailMessage` instances (or subclasses),
|
a list of :class:`~django.core.mail.EmailMessage` instances (or subclasses),
|
||||||
|
@ -539,11 +539,11 @@ and sends them all using a single connection.
|
||||||
|
|
||||||
For example, if you have a function called ``get_notification_email()`` that
|
For example, if you have a function called ``get_notification_email()`` that
|
||||||
returns a list of :class:`~django.core.mail.EmailMessage` objects representing
|
returns a list of :class:`~django.core.mail.EmailMessage` objects representing
|
||||||
some periodic e-mail you wish to send out, you could send these e-mails using
|
some periodic email you wish to send out, you could send these emails using
|
||||||
a single call to send_messages::
|
a single call to send_messages::
|
||||||
|
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
connection = mail.get_connection() # Use default e-mail connection
|
connection = mail.get_connection() # Use default email connection
|
||||||
messages = get_notification_email()
|
messages = get_notification_email()
|
||||||
connection.send_messages(messages)
|
connection.send_messages(messages)
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ In this example, the call to ``send_messages()`` opens a connection on the
|
||||||
backend, sends the list of messages, and then closes the connection again.
|
backend, sends the list of messages, and then closes the connection again.
|
||||||
|
|
||||||
The second approach is to use the ``open()`` and ``close()`` methods on the
|
The second approach is to use the ``open()`` and ``close()`` methods on the
|
||||||
e-mail backend to manually control the connection. ``send_messages()`` will not
|
email backend to manually control the connection. ``send_messages()`` will not
|
||||||
manually open or close the connection if it is already open, so if you
|
manually open or close the connection if it is already open, so if you
|
||||||
manually open the connection, you can control when it is closed. For example::
|
manually open the connection, you can control when it is closed. For example::
|
||||||
|
|
||||||
|
@ -561,10 +561,10 @@ manually open the connection, you can control when it is closed. For example::
|
||||||
# Manually open the connection
|
# Manually open the connection
|
||||||
connection.open()
|
connection.open()
|
||||||
|
|
||||||
# Construct an e-mail message that uses the connection
|
# Construct an email message that uses the connection
|
||||||
email1 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
email1 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
||||||
['to1@example.com'], connection=connection)
|
['to1@example.com'], connection=connection)
|
||||||
email1.send() # Send the e-mail
|
email1.send() # Send the email
|
||||||
|
|
||||||
# Construct two more messages
|
# Construct two more messages
|
||||||
email2 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
email2 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
||||||
|
@ -572,42 +572,42 @@ manually open the connection, you can control when it is closed. For example::
|
||||||
email3 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
email3 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
||||||
['to3@example.com'])
|
['to3@example.com'])
|
||||||
|
|
||||||
# Send the two e-mails in a single call -
|
# Send the two emails in a single call -
|
||||||
connection.send_messages([email2, email3])
|
connection.send_messages([email2, email3])
|
||||||
# The connection was already open so send_messages() doesn't close it.
|
# The connection was already open so send_messages() doesn't close it.
|
||||||
# We need to manually close the connection.
|
# We need to manually close the connection.
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
Testing e-mail sending
|
Testing email sending
|
||||||
======================
|
======================
|
||||||
|
|
||||||
There are times when you do not want Django to send e-mails at
|
There are times when you do not want Django to send emails at
|
||||||
all. For example, while developing a Web site, you probably don't want
|
all. For example, while developing a Web site, you probably don't want
|
||||||
to send out thousands of e-mails -- but you may want to validate that
|
to send out thousands of emails -- but you may want to validate that
|
||||||
e-mails will be sent to the right people under the right conditions,
|
emails will be sent to the right people under the right conditions,
|
||||||
and that those e-mails will contain the correct content.
|
and that those emails will contain the correct content.
|
||||||
|
|
||||||
The easiest way to test your project's use of e-mail is to use the ``console``
|
The easiest way to test your project's use of email is to use the ``console``
|
||||||
e-mail backend. This backend redirects all e-mail to stdout, allowing you to
|
email backend. This backend redirects all email to stdout, allowing you to
|
||||||
inspect the content of mail.
|
inspect the content of mail.
|
||||||
|
|
||||||
The ``file`` e-mail backend can also be useful during development -- this backend
|
The ``file`` email backend can also be useful during development -- this backend
|
||||||
dumps the contents of every SMTP connection to a file that can be inspected
|
dumps the contents of every SMTP connection to a file that can be inspected
|
||||||
at your leisure.
|
at your leisure.
|
||||||
|
|
||||||
Another approach is to use a "dumb" SMTP server that receives the e-mails
|
Another approach is to use a "dumb" SMTP server that receives the emails
|
||||||
locally and displays them to the terminal, but does not actually send
|
locally and displays them to the terminal, but does not actually send
|
||||||
anything. Python has a built-in way to accomplish this with a single command::
|
anything. Python has a built-in way to accomplish this with a single command::
|
||||||
|
|
||||||
python -m smtpd -n -c DebuggingServer localhost:1025
|
python -m smtpd -n -c DebuggingServer localhost:1025
|
||||||
|
|
||||||
This command will start a simple SMTP server listening on port 1025 of
|
This command will start a simple SMTP server listening on port 1025 of
|
||||||
localhost. This server simply prints to standard output all e-mail headers and
|
localhost. This server simply prints to standard output all email headers and
|
||||||
the e-mail body. You then only need to set the :setting:`EMAIL_HOST` and
|
the email body. You then only need to set the :setting:`EMAIL_HOST` and
|
||||||
:setting:`EMAIL_PORT` accordingly, and you are set.
|
:setting:`EMAIL_PORT` accordingly, and you are set.
|
||||||
|
|
||||||
For a more detailed discussion of testing and processing of e-mails locally,
|
For a more detailed discussion of testing and processing of emails locally,
|
||||||
see the Python documentation on the `SMTP Server`_.
|
see the Python documentation on the `SMTP Server`_.
|
||||||
|
|
||||||
.. _SMTP Server: http://docs.python.org/library/smtpd.html
|
.. _SMTP Server: http://docs.python.org/library/smtpd.html
|
||||||
|
@ -619,7 +619,7 @@ SMTPConnection
|
||||||
|
|
||||||
.. deprecated:: 1.2
|
.. deprecated:: 1.2
|
||||||
|
|
||||||
The ``SMTPConnection`` class has been deprecated in favor of the generic e-mail
|
The ``SMTPConnection`` class has been deprecated in favor of the generic email
|
||||||
backend API.
|
backend API.
|
||||||
|
|
||||||
For backwards compatibility ``SMTPConnection`` is still available in
|
For backwards compatibility ``SMTPConnection`` is still available in
|
||||||
|
|
|
@ -36,7 +36,7 @@ The library deals with these concepts:
|
||||||
|
|
||||||
Field
|
Field
|
||||||
A class that is responsible for doing validation, e.g.
|
A class that is responsible for doing validation, e.g.
|
||||||
an ``EmailField`` that makes sure its data is a valid e-mail address.
|
an ``EmailField`` that makes sure its data is a valid email address.
|
||||||
|
|
||||||
Form
|
Form
|
||||||
A collection of fields that knows how to validate itself and
|
A collection of fields that knows how to validate itself and
|
||||||
|
@ -163,7 +163,7 @@ Extending the above example, here's how the form data could be processed:
|
||||||
send_mail(subject, message, sender, recipients)
|
send_mail(subject, message, sender, recipients)
|
||||||
return HttpResponseRedirect('/thanks/') # Redirect after POST
|
return HttpResponseRedirect('/thanks/') # Redirect after POST
|
||||||
|
|
||||||
For more on sending e-mail from Django, see :doc:`/topics/email`.
|
For more on sending email from Django, see :doc:`/topics/email`.
|
||||||
|
|
||||||
Displaying a form using a template
|
Displaying a form using a template
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
@ -224,7 +224,7 @@ above example::
|
||||||
{{ form.non_field_errors }}
|
{{ form.non_field_errors }}
|
||||||
<div class="fieldWrapper">
|
<div class="fieldWrapper">
|
||||||
{{ form.subject.errors }}
|
{{ form.subject.errors }}
|
||||||
<label for="id_subject">E-mail subject:</label>
|
<label for="id_subject">Email subject:</label>
|
||||||
{{ form.subject }}
|
{{ form.subject }}
|
||||||
</div>
|
</div>
|
||||||
<div class="fieldWrapper">
|
<div class="fieldWrapper">
|
||||||
|
@ -288,11 +288,11 @@ Within this loop, ``{{ field }}`` is an instance of :class:`BoundField`.
|
||||||
templates:
|
templates:
|
||||||
|
|
||||||
``{{ field.label }}``
|
``{{ field.label }}``
|
||||||
The label of the field, e.g. ``E-mail address``.
|
The label of the field, e.g. ``Email address``.
|
||||||
|
|
||||||
``{{ field.label_tag }}``
|
``{{ field.label_tag }}``
|
||||||
The field's label wrapped in the appropriate HTML ``<label>`` tag,
|
The field's label wrapped in the appropriate HTML ``<label>`` tag,
|
||||||
e.g. ``<label for="id_email">E-mail address</label>``
|
e.g. ``<label for="id_email">Email address</label>``
|
||||||
|
|
||||||
``{{ field.html_name }}``
|
``{{ field.html_name }}``
|
||||||
The name of the field that will be used in the input element's name
|
The name of the field that will be used in the input element's name
|
||||||
|
|
|
@ -327,7 +327,7 @@ This logging configuration does the following things:
|
||||||
message to stdout. This handler uses the `simple` output
|
message to stdout. This handler uses the `simple` output
|
||||||
format.
|
format.
|
||||||
|
|
||||||
* ``mail_admins``, an AdminEmailHandler, which will e-mail any
|
* ``mail_admins``, an AdminEmailHandler, which will email any
|
||||||
``ERROR`` level message to the site admins. This handler uses
|
``ERROR`` level message to the site admins. This handler uses
|
||||||
the ``special`` filter.
|
the ``special`` filter.
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ This logging configuration does the following things:
|
||||||
handlers -- the ``console``, and ``mail_admins``. This
|
handlers -- the ``console``, and ``mail_admins``. This
|
||||||
means that all ``INFO`` level messages (or higher) will be
|
means that all ``INFO`` level messages (or higher) will be
|
||||||
printed to the console; ``ERROR`` and ``CRITICAL``
|
printed to the console; ``ERROR`` and ``CRITICAL``
|
||||||
messages will also be output via e-mail.
|
messages will also be output via email.
|
||||||
|
|
||||||
.. admonition:: Custom handlers and circular imports
|
.. admonition:: Custom handlers and circular imports
|
||||||
|
|
||||||
|
@ -474,17 +474,17 @@ Python logging module.
|
||||||
|
|
||||||
.. class:: AdminEmailHandler([include_html=False])
|
.. class:: AdminEmailHandler([include_html=False])
|
||||||
|
|
||||||
This handler sends an e-mail to the site admins for each log
|
This handler sends an email to the site admins for each log
|
||||||
message it receives.
|
message it receives.
|
||||||
|
|
||||||
If the log record contains a ``request`` attribute, the full details
|
If the log record contains a ``request`` attribute, the full details
|
||||||
of the request will be included in the e-mail.
|
of the request will be included in the email.
|
||||||
|
|
||||||
If the log record contains stack trace information, that stack
|
If the log record contains stack trace information, that stack
|
||||||
trace will be included in the e-mail.
|
trace will be included in the email.
|
||||||
|
|
||||||
The ``include_html`` argument of ``AdminEmailHandler`` is used to
|
The ``include_html`` argument of ``AdminEmailHandler`` is used to
|
||||||
control whether the traceback e-mail includes an HTML attachment
|
control whether the traceback email includes an HTML attachment
|
||||||
containing the full content of the debug Web page that would have been
|
containing the full content of the debug Web page that would have been
|
||||||
produced if ``DEBUG`` were ``True``. To set this value in your
|
produced if ``DEBUG`` were ``True``. To set this value in your
|
||||||
configuration, include it in the handler definition for
|
configuration, include it in the handler definition for
|
||||||
|
@ -498,12 +498,12 @@ Python logging module.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Note that this HTML version of the e-mail contains a full traceback,
|
Note that this HTML version of the email contains a full traceback,
|
||||||
with names and values of local variables at each level of the stack, plus
|
with names and values of local variables at each level of the stack, plus
|
||||||
the values of your Django settings. This information is potentially very
|
the values of your Django settings. This information is potentially very
|
||||||
sensitive, and you may not want to send it over e-mail. Consider using
|
sensitive, and you may not want to send it over email. Consider using
|
||||||
something such as `django-sentry`_ to get the best of both worlds -- the
|
something such as `django-sentry`_ to get the best of both worlds -- the
|
||||||
rich information of full tracebacks plus the security of *not* sending the
|
rich information of full tracebacks plus the security of *not* sending the
|
||||||
information over e-mail.
|
information over email.
|
||||||
|
|
||||||
.. _django-sentry: http://pypi.python.org/pypi/django-sentry
|
.. _django-sentry: http://pypi.python.org/pypi/django-sentry
|
||||||
|
|
|
@ -184,7 +184,7 @@ registered more than once, and thus called multiples times for a single signal
|
||||||
event.
|
event.
|
||||||
|
|
||||||
If this behavior is problematic (such as when using signals to
|
If this behavior is problematic (such as when using signals to
|
||||||
send an e-mail whenever a model is saved), pass a unique identifier as
|
send an email whenever a model is saved), pass a unique identifier as
|
||||||
the ``dispatch_uid`` argument to identify your receiver function. This
|
the ``dispatch_uid`` argument to identify your receiver function. This
|
||||||
identifier will usually be a string, although any hashable object will
|
identifier will usually be a string, although any hashable object will
|
||||||
suffice. The end result is that your receiver function will only be
|
suffice. The end result is that your receiver function will only be
|
||||||
|
|
|
@ -68,7 +68,7 @@ explained later in this document.::
|
||||||
|
|
||||||
Why use a text-based template instead of an XML-based one (like Zope's
|
Why use a text-based template instead of an XML-based one (like Zope's
|
||||||
TAL)? We wanted Django's template language to be usable for more than
|
TAL)? We wanted Django's template language to be usable for more than
|
||||||
just XML/HTML templates. At World Online, we use it for e-mails,
|
just XML/HTML templates. At World Online, we use it for emails,
|
||||||
JavaScript and CSV. You can use the template language for any text-based
|
JavaScript and CSV. You can use the template language for any text-based
|
||||||
format.
|
format.
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ contain data that you *intend* to be rendered as raw HTML, in which case you
|
||||||
don't want their contents to be escaped. For example, you might store a blob of
|
don't want their contents to be escaped. For example, you might store a blob of
|
||||||
HTML in your database and want to embed that directly into your template. Or,
|
HTML in your database and want to embed that directly into your template. Or,
|
||||||
you might be using Django's template system to produce text that is *not* HTML
|
you might be using Django's template system to produce text that is *not* HTML
|
||||||
-- like an e-mail message, for instance.
|
-- like an email message, for instance.
|
||||||
|
|
||||||
For individual variables
|
For individual variables
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -1351,9 +1351,9 @@ Emptying the test outbox
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
If you use Django's custom ``TestCase`` class, the test runner will clear the
|
If you use Django's custom ``TestCase`` class, the test runner will clear the
|
||||||
contents of the test e-mail outbox at the start of each test case.
|
contents of the test email outbox at the start of each test case.
|
||||||
|
|
||||||
For more detail on e-mail services during tests, see `E-mail services`_.
|
For more detail on email services during tests, see `Email services`_.
|
||||||
|
|
||||||
Assertions
|
Assertions
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
@ -1463,30 +1463,30 @@ cause of an failure in your test suite.
|
||||||
|
|
||||||
.. _topics-testing-email:
|
.. _topics-testing-email:
|
||||||
|
|
||||||
E-mail services
|
Email services
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
If any of your Django views send e-mail using :doc:`Django's e-mail
|
If any of your Django views send email using :doc:`Django's email
|
||||||
functionality </topics/email>`, you probably don't want to send e-mail each time
|
functionality </topics/email>`, you probably don't want to send email each time
|
||||||
you run a test using that view. For this reason, Django's test runner
|
you run a test using that view. For this reason, Django's test runner
|
||||||
automatically redirects all Django-sent e-mail to a dummy outbox. This lets you
|
automatically redirects all Django-sent email to a dummy outbox. This lets you
|
||||||
test every aspect of sending e-mail -- from the number of messages sent to the
|
test every aspect of sending email -- from the number of messages sent to the
|
||||||
contents of each message -- without actually sending the messages.
|
contents of each message -- without actually sending the messages.
|
||||||
|
|
||||||
The test runner accomplishes this by transparently replacing the normal
|
The test runner accomplishes this by transparently replacing the normal
|
||||||
email backend with a testing backend.
|
email backend with a testing backend.
|
||||||
(Don't worry -- this has no effect on any other e-mail senders outside of
|
(Don't worry -- this has no effect on any other email senders outside of
|
||||||
Django, such as your machine's mail server, if you're running one.)
|
Django, such as your machine's mail server, if you're running one.)
|
||||||
|
|
||||||
.. currentmodule:: django.core.mail
|
.. currentmodule:: django.core.mail
|
||||||
|
|
||||||
.. data:: django.core.mail.outbox
|
.. data:: django.core.mail.outbox
|
||||||
|
|
||||||
During test running, each outgoing e-mail is saved in
|
During test running, each outgoing email is saved in
|
||||||
``django.core.mail.outbox``. This is a simple list of all
|
``django.core.mail.outbox``. This is a simple list of all
|
||||||
:class:`~django.core.mail.EmailMessage` instances that have been sent.
|
:class:`~django.core.mail.EmailMessage` instances that have been sent.
|
||||||
The ``outbox`` attribute is a special attribute that is created *only* when
|
The ``outbox`` attribute is a special attribute that is created *only* when
|
||||||
the ``locmem`` e-mail backend is used. It doesn't normally exist as part of the
|
the ``locmem`` email backend is used. It doesn't normally exist as part of the
|
||||||
:mod:`django.core.mail` module and you can't import it directly. The code
|
:mod:`django.core.mail` module and you can't import it directly. The code
|
||||||
below shows how to access this attribute correctly.
|
below shows how to access this attribute correctly.
|
||||||
|
|
||||||
|
@ -1741,7 +1741,7 @@ utility methods in the ``django.test.utils`` module.
|
||||||
.. function:: teardown_test_environment()
|
.. function:: teardown_test_environment()
|
||||||
|
|
||||||
Performs any global post-test teardown, such as removing the black
|
Performs any global post-test teardown, such as removing the black
|
||||||
magic hooks into the template system and restoring normal e-mail
|
magic hooks into the template system and restoring normal email
|
||||||
services.
|
services.
|
||||||
|
|
||||||
The creation module of the database backend (``connection.creation``)
|
The creation module of the database backend (``connection.creation``)
|
||||||
|
|
|
@ -631,7 +631,7 @@ class AdminViewPermissionsTest(TestCase):
|
||||||
self.assertFalse(login.context)
|
self.assertFalse(login.context)
|
||||||
self.client.get('/test_admin/admin/logout/')
|
self.client.get('/test_admin/admin/logout/')
|
||||||
|
|
||||||
# Test if user enters e-mail address
|
# Test if user enters email address
|
||||||
request = self.client.get('/test_admin/admin/')
|
request = self.client.get('/test_admin/admin/')
|
||||||
self.assertEqual(request.status_code, 200)
|
self.assertEqual(request.status_code, 200)
|
||||||
login = self.client.post('/test_admin/admin/', self.super_email_login)
|
login = self.client.post('/test_admin/admin/', self.super_email_login)
|
||||||
|
@ -641,7 +641,7 @@ class AdminViewPermissionsTest(TestCase):
|
||||||
self.assertContains(login, "Please enter a correct username and password.")
|
self.assertContains(login, "Please enter a correct username and password.")
|
||||||
new_user = User(username='jondoe', password='secret', email='super@example.com')
|
new_user = User(username='jondoe', password='secret', email='super@example.com')
|
||||||
new_user.save()
|
new_user.save()
|
||||||
# check to ensure if there are multiple e-mail addresses a user doesn't get a 500
|
# check to ensure if there are multiple email addresses a user doesn't get a 500
|
||||||
login = self.client.post('/test_admin/admin/', self.super_email_login)
|
login = self.client.post('/test_admin/admin/', self.super_email_login)
|
||||||
self.assertContains(login, "Please enter a correct username and password.")
|
self.assertContains(login, "Please enter a correct username and password.")
|
||||||
|
|
||||||
|
@ -1227,7 +1227,7 @@ class SecureViewTests(TestCase):
|
||||||
# make sure the view removes test cookie
|
# make sure the view removes test cookie
|
||||||
self.assertEqual(self.client.session.test_cookie_worked(), False)
|
self.assertEqual(self.client.session.test_cookie_worked(), False)
|
||||||
|
|
||||||
# Test if user enters e-mail address
|
# Test if user enters email address
|
||||||
request = self.client.get('/test_admin/admin/secure-view/')
|
request = self.client.get('/test_admin/admin/secure-view/')
|
||||||
self.assertEqual(request.status_code, 200)
|
self.assertEqual(request.status_code, 200)
|
||||||
login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login)
|
login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login)
|
||||||
|
@ -1237,7 +1237,7 @@ class SecureViewTests(TestCase):
|
||||||
self.assertContains(login, "Please enter a correct username and password.")
|
self.assertContains(login, "Please enter a correct username and password.")
|
||||||
new_user = User(username='jondoe', password='secret', email='super@example.com')
|
new_user = User(username='jondoe', password='secret', email='super@example.com')
|
||||||
new_user.save()
|
new_user.save()
|
||||||
# check to ensure if there are multiple e-mail addresses a user doesn't get a 500
|
# check to ensure if there are multiple email addresses a user doesn't get a 500
|
||||||
login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login)
|
login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login)
|
||||||
self.assertContains(login, "Please enter a correct username and password.")
|
self.assertContains(login, "Please enter a correct username and password.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue