EmailMessage
A container for email information.
Attributes
| Attribute | Type | Description |
|---|---|---|
| content_subtype | string = "plain" | The subtype of the MIME content type for the email body, defaulting to "plain". |
| encoding | string = null | Undocumented charset to use for text/* message bodies and attachments. If None, defaults to settings.DEFAULT_CHARSET. |
Constructor
Signature
def EmailMessage(
subject: str = "",
body: str = "",
from_email: str = None,
to: list = None,
bcc: list = None,
connection: object = None,
attachments: list = None,
headers: dict = None,
cc: list = None,
reply_to: list = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| subject | str = "" | The subject line of the email. |
| body | str = "" | The body text of the email. |
| from_email | str = None | The sender's address. Defaults to settings.DEFAULT_FROM_EMAIL if not provided. |
| to | list = None | A list or tuple of recipient addresses. |
| bcc | list = None | A list or tuple of blind carbon copy recipient addresses. |
| connection | object = None | The email backend instance to use for sending the mail (deprecated). |
| attachments | list = None | A list of attachments to put on the message. |
| headers | dict = None | A dictionary of extra headers to put on the message. |
| cc | list = None | A list or tuple of carbon copy recipient addresses. |
| reply_to | list = None | A list or tuple of reply-to addresses. |
Signature
def EmailMessage(
subject: string = "",
body: string = "",
from_email: string = null,
to: list = null,
bcc: list = null,
connection: object = null,
attachments: list = null,
headers: dict = null,
cc: list = null,
reply_to: list = null
)
Parameters
| Name | Type | Description |
|---|---|---|
| subject | string = "" | The subject line of the email |
| body | string = "" | The main text content of the email message |
| from_email | string = null | The sender's email address; defaults to settings.DEFAULT_FROM_EMAIL if not provided |
| to | list = null | A list or tuple of recipient email addresses |
| bcc | list = null | A list or tuple of blind carbon copy recipient email addresses |
| connection | object = null | Deprecated; the email backend instance to use for sending this message |
| attachments | list = null | A list of attachments, which can be MIMEPart instances or tuples of (filename, content, mimetype) |
| headers | dict = null | A dictionary of extra headers to put on the message |
| cc | list = null | A list or tuple of carbon copy recipient email addresses |
| reply_to | list = null | A list or tuple of reply-to email addresses |
Methods
connection()
@classmethod
def connection() - > object
Accesses or sets the deprecated connection attribute used for sending the email.
Returns
| Type | Description |
|---|---|
object | The email backend connection instance |
message()
@classmethod
def message(
policy: email.policy.Policy
) - > email.message.EmailMessage
Constructs and returns a native Python email.message.EmailMessage object based on the current instance state.
Parameters
| Name | Type | Description |
|---|---|---|
| policy | email.policy.Policy | The email policy used to control how the message is constructed and serialized |
Returns
| Type | Description |
|---|---|
email.message.EmailMessage | A fully populated email message object ready for serialization or sending |
recipients()
@classmethod
def recipients() - > list
Return a list of all recipients of the email (includes direct addressees as well as Cc and Bcc entries).
Returns
| Type | Description |
|---|---|
list | A list of all unique email addresses found in the To, Cc, and Bcc fields |
send()
@classmethod
def send(
fail_silently: boolean = false,
using: string = null
) - > int
Send the email message.
Parameters
| Name | Type | Description |
|---|---|---|
| fail_silently | boolean = false | Whether to suppress exceptions during the sending process |
| using | string = null | The alias of the mailer configuration to use for sending |
Returns
| Type | Description |
|---|---|
int | The number of messages sent (typically 1 if successful, 0 if no recipients) |
attach()
@classmethod
def attach(
filename: string = null,
content: any = null,
mimetype: string = null
) - > null
Attach a file with the given filename and content. The filename can be omitted and the mimetype is guessed, if not provided.
Parameters
| Name | Type | Description |
|---|---|---|
| filename | string = null | The name of the file to be displayed in the email; can also be a MIMEPart instance |
| content | any = null | The raw file data or text content to attach |
| mimetype | string = null | The explicit MIME type for the attachment; if omitted, it is guessed from the filename |
Returns
| Type | Description |
|---|---|
null | null |
attach_file()
@classmethod
def attach_file(
path: string,
mimetype: string = null
) - > null
Attach a file from the filesystem.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | The filesystem path to the file that should be attached |
| mimetype | string = null | The explicit MIME type for the file; if omitted, it is guessed from the file extension |
Returns
| Type | Description |
|---|---|
null | null |