| 303 | | It is often useful to include multiple versions of the content in an e-mail. |
|---|
| 304 | | For instance, sending both text and HTML versions of an e-mail. You can do |
|---|
| 305 | | this using the ``EmailMultiAlternatives`` class. This sub-class of |
|---|
| 306 | | ``EmailMessage`` has an ``attach_alternative()`` method for including |
|---|
| 307 | | extra versions of the message body in the e-mail. All the other methods |
|---|
| 308 | | (including the class initialization) are inherited directly from |
|---|
| | 303 | It can be useful to include multiple versions of the content in an e-mail; |
|---|
| | 304 | the classic example is to send both text and HTML versions of a message. With |
|---|
| | 305 | Django's e-mail library, you can do this using the ``EmailMultiAlternatives`` |
|---|
| | 306 | class. This subclass of ``EmailMessage`` has an ``attach_alternative()`` method |
|---|
| | 307 | for including extra versions of the message body in the e-mail. All the other |
|---|
| | 308 | methods (including the class initialization) are inherited directly from |
|---|
| 315 | | subject, from_email, to = ... |
|---|
| 316 | | text_content = "This is an important message." |
|---|
| 317 | | html_content = "<p>This is an <strong>important</strong> message." |
|---|
| | 315 | subject, from_email, to = 'hello', 'from@example.com', 'to@example.com' |
|---|
| | 316 | text_content = 'This is an important message.' |
|---|
| | 317 | html_content = '<p>This is an <strong>important</strong> message.' |
|---|
| 323 | | ``"text/plain"``. It is good practice to leave this alone, since it guarantees |
|---|
| 324 | | that any recipient will be able to read the e-mail, regardless of their mail |
|---|
| 325 | | client. However, if you are confident that your recipients can handle an |
|---|
| 326 | | alternative content type, you can use the ``content_subtype`` attribute on the |
|---|
| 327 | | ``EmailMessage`` class to change the main content type. The major type will |
|---|
| 328 | | always be ``"text"``, but you can change to the subtype. For example:: |
|---|
| | 323 | ``"text/plain"``. It is good practice to leave this alone, because it |
|---|
| | 324 | guarantees that any recipient will be able to read the e-mail, regardless of |
|---|
| | 325 | their mail client. However, if you are confident that your recipients can |
|---|
| | 326 | handle an alternative content type, you can use the ``content_subtype`` |
|---|
| | 327 | attribute on the ``EmailMessage`` class to change the main content type. The |
|---|
| | 328 | major type will always be ``"text"``, but you can change it to the subtype. For |
|---|
| | 329 | example:: |
|---|