Skip to content

Commit 014be2f

Browse files
Dani Fornonsfelixxm
authored andcommitted
Fixed #36591 -- Removed unnecessary dotted paths in email docs.
1 parent 0ce1084 commit 014be2f

1 file changed

Lines changed: 52 additions & 64 deletions

File tree

docs/topics/email.txt

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,12 @@ can be ``0`` or ``1`` since it can only send one message).
133133
(subject, message, from_email, recipient_list)
134134

135135
``fail_silently``, ``auth_user``, ``auth_password`` and ``connection`` have the
136-
same functions as in :func:`~django.core.mail.send_mail`. They must be given
137-
as keyword arguments if used.
136+
same functions as in :func:`send_mail`. They must be given as keyword arguments
137+
if used.
138138

139139
Each separate element of ``datatuple`` results in a separate email message.
140-
As in :func:`~django.core.mail.send_mail`, recipients in the same
141-
``recipient_list`` will all see the other addresses in the email messages'
142-
"To:" field.
140+
As in :func:`send_mail`, recipients in the same ``recipient_list`` will all see
141+
the other addresses in the email messages' "To:" field.
143142

144143
For example, the following code would send two different messages to
145144
two different sets of recipients; however, only one connection to the
@@ -169,12 +168,10 @@ The return value will be the number of successfully delivered messages.
169168
``send_mass_mail()`` vs. ``send_mail()``
170169
----------------------------------------
171170

172-
The main difference between :func:`~django.core.mail.send_mass_mail` and
173-
:func:`~django.core.mail.send_mail` is that
174-
:func:`~django.core.mail.send_mail` opens a connection to the mail server
175-
each time it's executed, while :func:`~django.core.mail.send_mass_mail` uses
176-
a single connection for all of its messages. This makes
177-
:func:`~django.core.mail.send_mass_mail` slightly more efficient.
171+
The main difference between :func:`send_mass_mail` and :func:`send_mail` is
172+
that :func:`send_mail` opens a connection to the mail server each time it's
173+
executed, while :func:`send_mass_mail` uses a single connection for all of its
174+
messages. This makes :func:`send_mass_mail` slightly more efficient.
178175

179176
``mail_admins()``
180177
=================
@@ -248,9 +245,9 @@ scripts generate.
248245
The Django email functions outlined above all protect against header injection
249246
by forbidding newlines in header values. If any ``subject``, ``from_email`` or
250247
``recipient_list`` contains a newline (in either Unix, Windows or Mac style),
251-
the email function (e.g. :func:`~django.core.mail.send_mail`) will raise
252-
:exc:`ValueError` and, hence, will not send the email. It's your responsibility
253-
to validate all data before passing it to the email functions.
248+
the email function (e.g. :func:`send_mail`) will raise :exc:`ValueError` and,
249+
hence, will not send the email. It's your responsibility to validate all data
250+
before passing it to the email functions.
254251

255252
If a ``message`` contains headers at the start of the string, the headers will
256253
be printed as the first bit of the email message.
@@ -291,27 +288,24 @@ from the request's POST data, sends that to admin@example.com and redirects to
291288
The ``EmailMessage`` class
292289
==========================
293290

294-
Django's :func:`~django.core.mail.send_mail` and
295-
:func:`~django.core.mail.send_mass_mail` functions are actually thin
296-
wrappers that make use of the :class:`~django.core.mail.EmailMessage` class.
291+
Django's :func:`send_mail` and :meth:`send_mass_mail` functions are actually
292+
thin wrappers that make use of the :class:`EmailMessage` class.
297293

298-
Not all features of the :class:`~django.core.mail.EmailMessage` class are
299-
available through the :func:`~django.core.mail.send_mail` and related
300-
wrapper functions. If you wish to use advanced features, such as BCC'ed
301-
recipients, file attachments, or multi-part email, you'll need to create
302-
:class:`~django.core.mail.EmailMessage` instances directly.
294+
Not all features of the :class:`EmailMessage` class are available through the
295+
:func:`send_mail` and related wrapper functions. If you wish to use advanced
296+
features, such as BCC'ed recipients, file attachments, or multi-part email,
297+
you'll need to create :class:`EmailMessage` instances directly.
303298

304299
.. note::
305-
This is a design feature. :func:`~django.core.mail.send_mail` and
306-
related functions were originally the only interface Django provided.
307-
However, the list of parameters they accepted was slowly growing over
308-
time. It made sense to move to a more object-oriented design for email
309-
messages and retain the original functions only for backwards
310-
compatibility.
300+
This is a design feature. :func:`send_mail` and related functions were
301+
originally the only interface Django provided. However, the list of
302+
parameters they accepted was slowly growing over time. It made sense to
303+
move to a more object-oriented design for email messages and retain the
304+
original functions only for backwards compatibility.
311305

312-
:class:`~django.core.mail.EmailMessage` is responsible for creating the email
313-
message itself. The :ref:`email backend <topic-email-backends>` is then
314-
responsible for sending the email.
306+
:class:`EmailMessage` is responsible for creating the email message itself. The
307+
:ref:`email backend <topic-email-backends>` is then responsible for sending the
308+
email.
315309

316310
For convenience, :class:`EmailMessage` provides a :meth:`~EmailMessage.send`
317311
method for sending a single email. If you need to send multiple messages, the
@@ -540,7 +534,7 @@ Sending multiple content versions
540534
It can be useful to include multiple versions of the content in an email; the
541535
classic example is to send both text and HTML versions of a message. With
542536
Django's email library, you can do this using the
543-
:class:`~django.core.mail.EmailMultiAlternatives` class.
537+
:class:`EmailMultiAlternatives` class.
544538

545539
.. class:: EmailMultiAlternatives
546540

@@ -551,7 +545,7 @@ Django's email library, you can do this using the
551545

552546
.. attribute:: alternatives
553547

554-
A list of :class:`~django.core.mail.EmailAlternative` named tuples.
548+
A list of :class:`EmailAlternative` named tuples.
555549
This is particularly useful in tests::
556550

557551
self.assertEqual(len(msg.alternatives), 1)
@@ -564,8 +558,7 @@ Django's email library, you can do this using the
564558
.. versionchanged:: 5.2
565559

566560
In older versions, ``alternatives`` was a list of regular tuples,
567-
as opposed to :class:`~django.core.mail.EmailAlternative` named
568-
tuples.
561+
as opposed to :class:`EmailAlternative` named tuples.
569562

570563
.. method:: attach_alternative(content, mimetype)
571564

@@ -618,15 +611,14 @@ Django's email library, you can do this using the
618611
Updating the default content type
619612
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
620613

621-
By default, the MIME type of the ``body`` parameter in an
622-
:class:`~django.core.mail.EmailMessage` is ``"text/plain"``. It is good
623-
practice to leave this alone, because it guarantees that any recipient will be
624-
able to read the email, regardless of their mail client. However, if you are
625-
confident that your recipients can handle an alternative content type, you can
626-
use the ``content_subtype`` attribute on the
627-
:class:`~django.core.mail.EmailMessage` class to change the main content type.
628-
The major type will always be ``"text"``, but you can change the
629-
subtype. For example::
614+
By default, the MIME type of the ``body`` parameter in an :class:`EmailMessage`
615+
is ``"text/plain"``. It is good practice to leave this alone, because it
616+
guarantees that any recipient will be able to read the email, regardless of
617+
their mail client. However, if you are confident that your recipients can
618+
handle an alternative content type, you can use the ``content_subtype``
619+
attribute on the :class:`EmailMessage` class to change the main content type.
620+
The major type will always be ``"text"``, but you can change the subtype. For
621+
example::
630622

631623
msg = EmailMessage(subject, html_content, from_email, [to])
632624
msg.content_subtype = "html" # Main content is now text/html
@@ -645,11 +637,10 @@ The email backend class has the following methods:
645637

646638
* ``close()`` closes the current email-sending connection.
647639

648-
* ``send_messages(email_messages)`` sends a list of
649-
:class:`~django.core.mail.EmailMessage` objects. If the connection is
650-
not open, this call will implicitly open the connection, and close the
651-
connection afterward. If the connection is already open, it will be
652-
left open after mail has been sent.
640+
* ``send_messages(email_messages)`` sends a list of :class:`EmailMessage`
641+
objects. If the connection is not open, this call will implicitly open the
642+
connection, and close the connection afterward. If the connection is already
643+
open, it will be left open after mail has been sent.
653644

654645
It can also be used as a context manager, which will automatically call
655646
``open()`` and ``close()`` as needed::
@@ -754,9 +745,8 @@ File backend
754745

755746
The file backend writes emails to a file. A new file is created for each new
756747
session that is opened on this backend. The directory to which the files are
757-
written is either taken from the :setting:`EMAIL_FILE_PATH` setting or from
758-
the ``file_path`` keyword when creating a connection with
759-
:func:`~django.core.mail.get_connection`.
748+
written is either taken from the :setting:`EMAIL_FILE_PATH` setting or from the
749+
``file_path`` keyword when creating a connection with :func:`get_connection`.
760750

761751
To specify this backend, put the following in your settings::
762752

@@ -772,10 +762,9 @@ In-memory backend
772762
~~~~~~~~~~~~~~~~~
773763

774764
The ``'locmem'`` backend stores messages in a special attribute of the
775-
``django.core.mail`` module. The ``outbox`` attribute is created when the
776-
first message is sent. It's a list with an
777-
:class:`~django.core.mail.EmailMessage` instance for each message that would
778-
be sent.
765+
``django.core.mail`` module. The ``outbox`` attribute is created when the first
766+
message is sent. It's a list with an :class:`EmailMessage` instance for each
767+
message that would be sent.
779768

780769
To specify this backend, put the following in your settings::
781770

@@ -812,11 +801,10 @@ the Python import path for your backend class.
812801
Custom email backends should subclass ``BaseEmailBackend`` that is located in
813802
the ``django.core.mail.backends.base`` module. A custom email backend must
814803
implement the ``send_messages(email_messages)`` method. This method receives a
815-
list of :class:`~django.core.mail.EmailMessage` instances and returns the
816-
number of successfully delivered messages. If your backend has any concept of
817-
a persistent session or connection, you should also implement the ``open()``
818-
and ``close()`` methods. Refer to ``smtp.EmailBackend`` for a reference
819-
implementation.
804+
list of :class:`EmailMessage` instances and returns the number of successfully
805+
delivered messages. If your backend has any concept of a persistent session or
806+
connection, you should also implement the ``open()`` and ``close()`` methods.
807+
Refer to ``smtp.EmailBackend`` for a reference implementation.
820808

821809
.. _topics-sending-multiple-emails:
822810

@@ -836,9 +824,9 @@ using that single connection. As a consequence, any :class:`connection
836824
<EmailMessage>` set on an individual message is ignored.
837825

838826
For example, if you have a function called ``get_notification_email()`` that
839-
returns a list of :class:`~django.core.mail.EmailMessage` objects representing
840-
some periodic email you wish to send out, you could send these emails using
841-
a single call to send_messages::
827+
returns a list of :class:`EmailMessage` objects representing some periodic
828+
email you wish to send out, you could send these emails using a single call to
829+
``send_messages()``::
842830

843831
from django.core import mail
844832

0 commit comments

Comments
 (0)