| 192 | | Django's `send_mail()` and `send_mass_mail()` functions are actually thin |
|---|
| 193 | | wrappers that make use of the `EmailMessage` and `SMTPConnection` classes in |
|---|
| 194 | | `django.mail`. If you ever need to customize the way Django sends email, you |
|---|
| 195 | | can subclass these two classes to suit your needs. |
|---|
| | 192 | Django's ``send_mail()`` and ``send_mass_mail()`` functions are actually thin |
|---|
| | 193 | wrappers that make use of the ``EmailMessage`` and ``SMTPConnection`` classes |
|---|
| | 194 | in ``django.mail``. If you ever need to customize the way Django sends email, |
|---|
| | 195 | you can subclass these two classes to suit your needs. |
|---|
| 201 | | need to create `EmailMessage` instances directly. |
|---|
| 202 | | |
|---|
| 203 | | In general, `EmailMessage` is responsible for creating the email message |
|---|
| 204 | | itself. `SMTPConnection` is responsible for the network connection side of the |
|---|
| 205 | | operation. This means you can reuse the same connection (an `SMTPConnection` |
|---|
| 206 | | instance) for multiple messages. |
|---|
| 207 | | |
|---|
| 208 | | The `EmailMessage` class has the following methods that you can use: |
|---|
| 209 | | |
|---|
| 210 | | * `send()` sends the message, using either the connection that is specified |
|---|
| 211 | | in the `connection` attribute, or creating a new connection if none already |
|---|
| | 201 | need to create ``EmailMessage`` instances directly. |
|---|
| | 202 | |
|---|
| | 203 | In general, ``EmailMessage`` is responsible for creating the email message |
|---|
| | 204 | itself. ``SMTPConnection`` is responsible for the network connection side of |
|---|
| | 205 | the operation. This means you can reuse the same connection (an |
|---|
| | 206 | ``SMTPConnection`` instance) for multiple messages. |
|---|
| | 207 | |
|---|
| | 208 | The ``EmailMessage`` class is initialised as follows:: |
|---|
| | 209 | |
|---|
| | 210 | email = EmailMessage(subject, body, from_email, to, bcc, connection) |
|---|
| | 211 | |
|---|
| | 212 | All of these parameters are optional. If ``from_email`` is omitted, the value |
|---|
| | 213 | from ``settings.DEFAULT_FROM_EMAIL`` is used. Both the ``to`` and ``bcc`` |
|---|
| | 214 | parameters are lists of addresses. |
|---|
| | 215 | |
|---|
| | 216 | The class has the following methods that you can use: |
|---|
| | 217 | |
|---|
| | 218 | * ``send()`` sends the message, using either the connection that is specified |
|---|
| | 219 | in the ``connection`` attribute, or creating a new connection if none already |
|---|
| 213 | | * `message()` constructs a `django.core.mail.SafeMIMEText` object (a |
|---|
| 214 | | sub-class of Python's `email.MIMEText.MIMEText` class) holding the message |
|---|
| 215 | | to be sent. If you ever need to extend the `EmailMessage` class, you will |
|---|
| 216 | | probably want to override this method to put the content you wish into the |
|---|
| 217 | | MIME object. |
|---|
| 218 | | |
|---|
| 219 | | The `SMTPConnection` class is initialized with the host, port, username and |
|---|
| | 221 | * ``message()`` constructs a ``django.core.mail.SafeMIMEText`` object (a |
|---|
| | 222 | sub-class of Python's ``email.MIMEText.MIMEText`` class) holding the |
|---|
| | 223 | message to be sent. If you ever need to extend the `EmailMessage` class, |
|---|
| | 224 | you will probably want to override this method to put the content you wish |
|---|
| | 225 | into the MIME object. |
|---|
| | 226 | * ``recipients()`` returns a lists of all the recipients of the message, |
|---|
| | 227 | whether they are recorded in the ``to`` or ``bcc`` attributes. This is |
|---|
| | 228 | another method you need to possibly override when sub-classing, since the |
|---|
| | 229 | SMTP server needs to be told the full list of recipients when the message |
|---|
| | 230 | is sent. If you add another way to specify recipients in your class, they |
|---|
| | 231 | need to be returned from this method as well. |
|---|
| | 232 | |
|---|
| | 233 | The ``SMTPConnection`` class is initialized with the host, port, username and |
|---|