Skip to main content

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

AttributeTypeDescription
alternativeslist = []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

NameTypeDescription
subjectstring = ""The subject line of the email.
bodystring = ""The main body text of the email.
from_email`stringnull` = null
to`listnull` = null
bcc`listnull` = null
connection`objectnull` = null
attachments`listnull` = null
headers`dictnull` = null
alternatives`listnull` = null
cc`listnull` = null
reply_to`listnull` = null

Methods


attach_alternative()

@classmethod
def attach_alternative(
content: string,
mimetype: string
) - > null

Attach an alternative content representation.

Parameters

NameTypeDescription
contentstringThe raw content of the alternative representation, such as an HTML string
mimetypestringThe MIME type of the content, for example 'text/html'

Returns

TypeDescription
nullNothing 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

NameTypeDescription
textstringThe substring to search for within the various message body representations

Returns

TypeDescription
booleanTrue if the text is found in the main body and all text-based alternatives, False otherwise