EmailMultiAlternatives
A version of EmailMessage that makes it easy to send multipart/alternative messages. For example, including text and HTML versions of the text is made easier.
Attributes
| Attribute | Type | Description |
|---|---|---|
| alternatives | list = [] | A list of EmailAlternative objects representing different content representations of the message, such as HTML versions of the text body. |
Constructor
Signature
def EmailMultiAlternatives(
subject: string = "",
body: string = "",
from_email: string | null = null,
to: list | null = null,
bcc: list | null = null,
connection: object | null = null,
attachments: list | null = null,
headers: dict | null = null,
alternatives: list | null = null,
cc: list | null = null,
reply_to: list | null = null
)
Parameters
| Name | Type | Description |
|---|---|---|
| subject | string = "" | The subject line of the email. |
| body | string = "" | The main body text of the email. |
| from_email | `string | null` = null |
| to | `list | null` = null |
| bcc | `list | null` = null |
| connection | `object | null` = null |
| attachments | `list | null` = null |
| headers | `dict | null` = null |
| alternatives | `list | null` = null |
| cc | `list | null` = null |
| reply_to | `list | null` = null |
Methods
attach_alternative()
@classmethod
def attach_alternative(
content: string,
mimetype: string
) - > null
Attach an alternative content representation.
Parameters
| Name | Type | Description |
|---|---|---|
| content | string | The raw content of the alternative representation, such as an HTML string |
| mimetype | string | The MIME type of the content, for example 'text/html' |
Returns
| Type | Description |
|---|---|
null | Nothing is returned; the alternative is appended to the internal list of message parts |
body_contains()
@classmethod
def body_contains(
text: string
) - > boolean
Checks that text occurs in the email body and in all attached MIME type text/* alternatives.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The substring to search for within the various message body representations |
Returns
| Type | Description |
|---|---|
boolean | True if the text is found in the main body and all text-based alternatives, False otherwise |