View source on GitHub
|
Main interface to the Mail API service.
Inherits From: expected_type
google.appengine.api.mail.EmailMessage(
mime_message: typing.Optional[typing.Union[typing.Text, bytes, typing.TextIO, email.
message.Message]] = None,
**kw
)
This class is used to programmatically build an email message to send via the
Mail API. To use this class, construct an instance, populate its fields and
call Send().
An EmailMessage can be built completely by the constructor:
EmailMessage(sender='sender@nowhere.com',
to='recipient@nowhere.com',
subject='a subject',
body='This is an email to you').Send()
You might want your application to build an email in different places
throughout the code. For this usage, EmailMessage is mutable:
message = EmailMessage()
message.sender = 'sender@nowhere.com'
message.to = ['recipient1@nowhere.com', 'recipient2@nowhere.com']
message.subject = 'a subject'
message.body = 'This is an email to you'
message.check_initialized()
message.send()
Attributes | |
|---|---|
original
|
Gets the original MIME message from which values were set. |
Methods
CheckInitialized
CheckInitialized()
Ensures that recipients have been specified.
Initialize
Initialize(
**kw
)
IsInitialized
IsInitialized()
Determines if EmailMessage is properly initialized.
Send
Send(
*args, **kwds
)
ToMIMEMessage
ToMIMEMessage()
ToProto
ToProto()
Performs more conversion of recipient fields to the protocol buffer.
| Returns | |
|---|---|
The MailMessage protocol version of the mail message, including sender
fields.
|
bodies
bodies(
content_type: typing.Text = None
)
Iterates over all bodies.
| Args | |
|---|---|
content_type
|
Content type on which to filter. This argument allows you to
select only specific types of content. You can use the base type or
the content type.
For example: |
| Yields | |
|---|---|
A (content_type, payload) tuple for HTML and body in that order.
|
check_initialized
check_initialized()
Provides additional checks to ensure that recipients have been specified.
| Raises | |
|---|---|
MissingRecipientError
|
If no recipients are specified in 'To', 'Cc', or 'Bcc'. |
initialize
initialize(
**kw
)
Keyword initialization.
This function sets all fields of the email message using the keyword arguments.
| Args | |
|---|---|
**kw
|
List of keyword properties as defined by PROPERTIES.
|
is_initialized
is_initialized()
Determines if EmailMessage is properly initialized.
| Returns | |
|---|---|
True if the message is properly initialized; otherwise returns False.
|
send
send(
make_sync_call=google.appengine.api.apiproxy_stub_map.MakeSyncCall
)
Sends an email message via the Mail API.
| Args | |
|---|---|
make_sync_call
|
Method that will make a synchronous call to the API proxy. |
to_mime_message
to_mime_message()
Generates a MIMEMultipart message from EmailMessage.
This function calls MailMessageToMessage after converting self to
the protocol buffer. The protocol buffer is better at handing corner cases
than the EmailMessage class.
| Returns | |
|---|---|
A MIMEMultipart message that represents the provided MailMessage.
|
| Raises | |
|---|---|
InvalidAttachmentTypeError
|
The attachment type was invalid. |
MissingSenderError
|
A sender was not specified. |
MissingSubjectError
|
A subject was not specified. |
MissingBodyError
|
A body was not specified. |
update_from_mime_message
update_from_mime_message(
mime_message
)
Copies information for recipients from a MIME message.
| Args | |
|---|---|
mime_message
|
The email.Message instance from which to copy information.
|
Class Variables | |
|---|---|
| ALLOWED_EMPTY_PROPERTIES |
|
| PROPERTIES |
|
View source on GitHub