@@ -20,14 +20,14 @@ In two lines::
20
20
send_mail('Subject here', 'Here is the message.', 'from@example.com',
21
21
['to@example.com'], fail_silently=False)
22
22
23
- Mail will be sent using the SMTP host and port specified in the `EMAIL_HOST`_
24
- and `EMAIL_PORT`_ settings. The `EMAIL_HOST_USER`_ and `EMAIL_HOST_PASSWORD`_
25
- settings, if set, will be used to authenticate to the SMTP server and the
26
- `EMAIL_USE_TLS`_ settings will control whether a secure connection is used.
23
+ Mail is sent using the SMTP host and port specified in the `EMAIL_HOST`_ and
24
+ `EMAIL_PORT`_ settings. The `EMAIL_HOST_USER`_ and `EMAIL_HOST_PASSWORD`_
25
+ settings, if set, are used to authenticate to the SMTP server, and the
26
+ `EMAIL_USE_TLS`_ setting controls whether a secure connection is used.
27
27
28
28
.. note::
29
29
30
- The character set of email sent with ``django.core.mail`` will be set to
30
+ The character set of e-mail sent with ``django.core.mail`` will be set to
31
31
the value of your `DEFAULT_CHARSET setting`_.
32
32
33
33
.. _DEFAULT_CHARSET setting: ../settings/#default-charset
@@ -37,7 +37,6 @@ settings, if set, will be used to authenticate to the SMTP server and the
37
37
.. _EMAIL_HOST_PASSWORD: ../settings/#email-host-password
38
38
.. _EMAIL_USE_TLS: ../settings/#email-use-tls
39
39
40
-
41
40
send_mail()
42
41
===========
43
42
@@ -193,57 +192,64 @@ The EmailMessage and SMTPConnection classes
193
192
194
193
Django's ``send_mail()`` and ``send_mass_mail()`` functions are actually thin
195
194
wrappers that make use of the ``EmailMessage`` and ``SMTPConnection`` classes
196
- in ``django.mail``. If you ever need to customize the way Django sends email,
197
- you can subclass these two classes to suit your needs.
195
+ in ``django.core. mail``. If you ever need to customize the way Django sends
196
+ e-mail, you can subclass these two classes to suit your needs.
198
197
199
198
.. note::
200
199
Not all features of the ``EmailMessage`` class are available through the
201
200
``send_mail()`` and related wrapper functions. If you wish to use advanced
202
- features such as including BCC recipients or multi-part email , you will
203
- need to create ``EmailMessage`` instances directly.
201
+ features, such as BCC'ed recipients or multi-part e-mail , you'll need to
202
+ create ``EmailMessage`` instances directly.
204
203
205
- In general, ``EmailMessage`` is responsible for creating the email message
204
+ In general, ``EmailMessage`` is responsible for creating the e-mail message
206
205
itself. ``SMTPConnection`` is responsible for the network connection side of
207
206
the operation. This means you can reuse the same connection (an
208
207
``SMTPConnection`` instance) for multiple messages.
209
208
210
- The ``EmailMessage`` class is initialised as follows::
209
+ The ``EmailMessage`` class is initialized as follows::
211
210
212
211
email = EmailMessage(subject, body, from_email, to, bcc, connection)
213
212
214
213
All of these parameters are optional. If ``from_email`` is omitted, the value
215
214
from ``settings.DEFAULT_FROM_EMAIL`` is used. Both the ``to`` and ``bcc``
216
- parameters are lists of addresses.
217
-
218
- The class has the following methods that you can use:
219
-
220
- * ``send()`` sends the message, using either the connection that is specified
221
- in the ``connection`` attribute, or creating a new connection if none already
222
- exists.
223
- * ``message()`` constructs a ``django.core.mail.SafeMIMEText`` object (a
224
- sub-class of Python's ``email.MIMEText.MIMEText`` class) holding the
225
- message to be sent. If you ever need to extend the `EmailMessage` class,
226
- you will probably want to override this method to put the content you wish
227
- into the MIME object.
228
- * ``recipients()`` returns a lists of all the recipients of the message,
229
- whether they are recorded in the ``to`` or ``bcc`` attributes. This is
230
- another method you need to possibly override when sub-classing, since the
231
- SMTP server needs to be told the full list of recipients when the message
232
- is sent. If you add another way to specify recipients in your class, they
233
- need to be returned from this method as well.
215
+ parameters are lists of addresses, as strings.
216
+
217
+ For example::
218
+
219
+ email = EmailMessage('Hello', 'Body goes here', 'from@example.com',
220
+ ['to1@example.com', 'to2@example.com'],
221
+ ['bcc@example.com'])
222
+
223
+ The class has the following methods:
224
+
225
+ * ``send()`` sends the message, using either the connection that is
226
+ specified in the ``connection`` attribute, or creating a new connection
227
+ if none already exists.
228
+
229
+ * ``message()`` constructs a ``django.core.mail.SafeMIMEText`` object (a
230
+ sub-class of Python's ``email.MIMEText.MIMEText`` class) holding the
231
+ message to be sent. If you ever need to extend the `EmailMessage` class,
232
+ you'll probably want to override this method to put the content you wish
233
+ into the MIME object.
234
+
235
+ * ``recipients()`` returns a list of all the recipients of the message,
236
+ whether they're recorded in the ``to`` or ``bcc`` attributes. This is
237
+ another method you might need to override when sub-classing, because the
238
+ SMTP server needs to be told the full list of recipients when the message
239
+ is sent. If you add another way to specify recipients in your class, they
240
+ need to be returned from this method as well.
234
241
235
242
The ``SMTPConnection`` class is initialized with the host, port, username and
236
243
password for the SMTP server. If you don't specify one or more of those
237
244
options, they are read from your settings file.
238
245
239
- If you are sending lots of messages at once, the ``send_messages()`` method of
240
- the ``SMTPConnection`` class will be useful. It takes a list of ``EmailMessage``
241
- instances (or sub-classes ) and sends them over a single connection. For
242
- example, if you have a function called ``get_notification_email()`` that returns a
243
- list of ``EmailMessage`` objects representing some periodic email you wish to
246
+ If you're sending lots of messages at once, the ``send_messages()`` method of
247
+ the ``SMTPConnection`` class is useful. It takes a list of ``EmailMessage``
248
+ instances (or subclasses ) and sends them over a single connection. For example,
249
+ if you have a function called ``get_notification_email()`` that returns a
250
+ list of ``EmailMessage`` objects representing some periodic e-mail you wish to
244
251
send out, you could send this with::
245
252
246
253
connection = SMTPConnection() # Use default settings for connection
247
254
messages = get_notification_email()
248
255
connection.send_messages(messages)
249
-
0 commit comments