| 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. |
|---|
| 202 | | features such as including BCC recipients or multi-part email, you will |
|---|
| 203 | | need to create ``EmailMessage`` instances directly. |
|---|
| 204 | | |
|---|
| 205 | | In general, ``EmailMessage`` is responsible for creating the email message |
|---|
| | 201 | features, such as BCC'ed recipients or multi-part e-mail, you'll need to |
|---|
| | 202 | create ``EmailMessage`` instances directly. |
|---|
| | 203 | |
|---|
| | 204 | In general, ``EmailMessage`` is responsible for creating the e-mail message |
|---|
| 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. |
|---|
| 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 |
|---|