Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Edited docs/email.txt changes from [5141] and other recent changesets

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5155 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 64adc413770c4762da5db697c4a332ac749cf4f3 1 parent 1889db4
@adrianholovaty adrianholovaty authored
Showing with 42 additions and 36 deletions.
  1. +42 −36 docs/email.txt
View
78 docs/email.txt
@@ -20,14 +20,14 @@ In two lines::
send_mail('Subject here', 'Here is the message.', 'from@example.com',
['to@example.com'], fail_silently=False)
-Mail will be sent using the SMTP host and port specified in the `EMAIL_HOST`_
-and `EMAIL_PORT`_ settings. The `EMAIL_HOST_USER`_ and `EMAIL_HOST_PASSWORD`_
-settings, if set, will be used to authenticate to the SMTP server and the
-`EMAIL_USE_TLS`_ settings will control whether a secure connection is used.
+Mail is sent using the SMTP host and port specified in the `EMAIL_HOST`_ and
+`EMAIL_PORT`_ settings. The `EMAIL_HOST_USER`_ and `EMAIL_HOST_PASSWORD`_
+settings, if set, are used to authenticate to the SMTP server, and the
+`EMAIL_USE_TLS`_ setting controls whether a secure connection is used.
.. note::
- The character set of email sent with ``django.core.mail`` will be set to
+ The character set of e-mail sent with ``django.core.mail`` will be set to
the value of your `DEFAULT_CHARSET setting`_.
.. _DEFAULT_CHARSET setting: ../settings/#default-charset
@@ -37,7 +37,6 @@ settings, if set, will be used to authenticate to the SMTP server and the
.. _EMAIL_HOST_PASSWORD: ../settings/#email-host-password
.. _EMAIL_USE_TLS: ../settings/#email-use-tls
-
send_mail()
===========
@@ -193,57 +192,64 @@ The EmailMessage and SMTPConnection classes
Django's ``send_mail()`` and ``send_mass_mail()`` functions are actually thin
wrappers that make use of the ``EmailMessage`` and ``SMTPConnection`` classes
-in ``django.mail``. If you ever need to customize the way Django sends email,
-you can subclass these two classes to suit your needs.
+in ``django.core.mail``. If you ever need to customize the way Django sends
+e-mail, you can subclass these two classes to suit your needs.
.. note::
Not all features of the ``EmailMessage`` class are available through the
``send_mail()`` and related wrapper functions. If you wish to use advanced
- features such as including BCC recipients or multi-part email, you will
- need to create ``EmailMessage`` instances directly.
+ features, such as BCC'ed recipients or multi-part e-mail, you'll need to
+ create ``EmailMessage`` instances directly.
-In general, ``EmailMessage`` is responsible for creating the email message
+In general, ``EmailMessage`` is responsible for creating the e-mail message
itself. ``SMTPConnection`` is responsible for the network connection side of
the operation. This means you can reuse the same connection (an
``SMTPConnection`` instance) for multiple messages.
-The ``EmailMessage`` class is initialised as follows::
+The ``EmailMessage`` class is initialized as follows::
email = EmailMessage(subject, body, from_email, to, bcc, connection)
All of these parameters are optional. If ``from_email`` is omitted, the value
from ``settings.DEFAULT_FROM_EMAIL`` is used. Both the ``to`` and ``bcc``
-parameters are lists of addresses.
-
-The class has the following methods that you can use:
-
- * ``send()`` sends the message, using either the connection that is specified
- in the ``connection`` attribute, or creating a new connection if none already
- exists.
- * ``message()`` constructs a ``django.core.mail.SafeMIMEText`` object (a
- sub-class of Python's ``email.MIMEText.MIMEText`` class) holding the
- message to be sent. If you ever need to extend the `EmailMessage` class,
- you will probably want to override this method to put the content you wish
- into the MIME object.
- * ``recipients()`` returns a lists of all the recipients of the message,
- whether they are recorded in the ``to`` or ``bcc`` attributes. This is
- another method you need to possibly override when sub-classing, since the
- SMTP server needs to be told the full list of recipients when the message
- is sent. If you add another way to specify recipients in your class, they
- need to be returned from this method as well.
+parameters are lists of addresses, as strings.
+
+For example::
+
+ email = EmailMessage('Hello', 'Body goes here', 'from@example.com',
+ ['to1@example.com', 'to2@example.com'],
+ ['bcc@example.com'])
+
+The class has the following methods:
+
+ * ``send()`` sends the message, using either the connection that is
+ specified in the ``connection`` attribute, or creating a new connection
+ if none already exists.
+
+ * ``message()`` constructs a ``django.core.mail.SafeMIMEText`` object (a
+ sub-class of Python's ``email.MIMEText.MIMEText`` class) holding the
+ message to be sent. If you ever need to extend the `EmailMessage` class,
+ you'll probably want to override this method to put the content you wish
+ into the MIME object.
+
+ * ``recipients()`` returns a list of all the recipients of the message,
+ whether they're recorded in the ``to`` or ``bcc`` attributes. This is
+ another method you might need to override when sub-classing, because the
+ SMTP server needs to be told the full list of recipients when the message
+ is sent. If you add another way to specify recipients in your class, they
+ need to be returned from this method as well.
The ``SMTPConnection`` class is initialized with the host, port, username and
password for the SMTP server. If you don't specify one or more of those
options, they are read from your settings file.
-If you are sending lots of messages at once, the ``send_messages()`` method of
-the ``SMTPConnection`` class will be useful. It takes a list of ``EmailMessage``
-instances (or sub-classes) and sends them over a single connection. For
-example, if you have a function called ``get_notification_email()`` that returns a
-list of ``EmailMessage`` objects representing some periodic email you wish to
+If you're sending lots of messages at once, the ``send_messages()`` method of
+the ``SMTPConnection`` class is useful. It takes a list of ``EmailMessage``
+instances (or subclasses) and sends them over a single connection. For example,
+if you have a function called ``get_notification_email()`` that returns a
+list of ``EmailMessage`` objects representing some periodic e-mail you wish to
send out, you could send this with::
connection = SMTPConnection() # Use default settings for connection
messages = get_notification_email()
connection.send_messages(messages)
-

0 comments on commit 64adc41

Please sign in to comment.
Something went wrong with that request. Please try again.