View source on GitHub |
Interface that sends email messages to all administrators via the Mail API.
Inherits From: expected_type
google.appengine.api.mail.AdminEmailMessage(
mime_message=None, **kw
)
This class is used to programmatically build an administrator email message to
be sent via the Mail API. To use the class, construct an instance, populate
its fields, and call Send()
.
Unlike normal email messages, addresses in the recipient fields are ignored and not used to send the message.
An AdminEmailMessage
can be built completely by the constructor:
AdminEmailMessage(sender='sender@nowhere.com',
subject='a subject',
body='This is an email to you').Send()
You might want your application to build an administrator email in different
places throughout the code. For this, AdminEmailMessage
is mutable:
message = AdminEmailMessage()
message.sender = 'sender@nowhere.com'
message.subject = 'a subject'
message.body = 'This is an email to you'
message.check_initialized()
message.send()
Args | |
---|---|
mime_message
|
The MIME message to initialize from. If the message is an
instance of email.message.Message , mime_message will take
ownership as specified the original message.
|
**kw
|
List of keyword properties as defined by PROPERTIES .
|
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()
Converts an email message to a protocol message.
Unicode strings are converted to UTF-8 for all fields.
This method is overridden by EmailMessage
to support the sender field.
Returns | |
---|---|
The MailMessage protocol version of the mail message.
|
Raises | |
---|---|
Decoding errors when using EncodedPayload objects.
|
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()
Checks if EmailMessage
is properly initialized.
This function tests if EmailMessage
meets the basic requirements to be
used with the Mail API. To function properly, this function requires that
the following fields must be set or have at least one value in the case of
multi-value fields:
- A subject must be set.
- A recipient must be specified.
- The message must contain a body.
- All bodies and attachments must decode properly.
This test does not include determining if the sender is actually authorized to send email for the application.
Raises | |
---|---|
InvalidAttachmentTypeError
|
The attachment type is invalid. |
MissingRecipientsError
|
No recipients were specified in the 'To', 'Cc', or 'Bcc' fields. |
MissingSenderError
|
A sender was not specified. |
MissingSubjectError
|
A subject was not specified. |
MissingBodyError
|
A body was not specified. |
PayloadEncodingError
|
The payload was not properly encoded. |
UnknownEncodingError
|
The payload encoding could not be determined. |
UnknownCharsetError
|
The character set of the payload could not be determined. |
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 from a MIME message.
Information from the email.Message
instance is set to the values of the
MIME message. This function will only copy values that it finds. Missing
values will not be copied, nor will those values overwrite old values with
blank values.
This object is not guaranteed to be initialized after this call.
Args | |
---|---|
mime_message
|
The email.Message instance from which to copy information.
|
Returns | |
---|---|
A MIME message instance of the mime_message .
|
Class Variables | |
---|---|
ALLOWED_EMPTY_PROPERTIES |
|
PROPERTIES |
|