Python 3.9 is now generally available.

google.appengine.api.mail.InboundEmailMessage

Receives a parsed email as it is recevied from an external source.

Inherits From: EmailMessage, expected_type

This class makes use of a date field and can store any number of additional bodies. These additional attributes make the email more flexible as required for incoming mail, where the developer has less control over the content.

Example:

Read mail message from CGI input.

message = InboundEmailMessage(sys.stdin.read()) logging.info('Received email message from %s at %s', message.sender, message.date) enriched_body = list(message.bodies('text/enriched'))[0]

... Do something with body ...

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.

original Gets the original MIME message from which values were set.

Methods

CheckInitialized

View source

Ensures that recipients have been specified.

Initialize

View source

IsInitialized

View source

Determines if EmailMessage is properly initialized.

Send

View source

ToMIMEMessage

View source

ToProto

View source

Performs more conversion of recipient fields to the protocol buffer.

Returns
The MailMessage protocol version of the mail message, including sender fields.

bodies

View source

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, content_type = 'text/html' matches only HTML content, and content_type = 'text' matches text of any kind.

Yields
A (content_type, payload) tuple for all bodies of a message, including the body, HTML, and all alternate_bodies, in that order.

check_initialized

View source

Provides additional checks to ensure that recipients have been specified.

Raises
MissingRecipientError If no recipients are specified in 'To', 'Cc', or 'Bcc'.

initialize

View source

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

View source

Determines if EmailMessage is properly initialized.

Returns
True if the message is properly initialized; otherwise returns False.

send

View source

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

View source

Converts a message to a MIME message.

This function adds additional headers from the inbound email.

Returns
The MIME message instance of a payload.

update_from_mime_message

View source

Updates the values of a MIME message.

This function copies over date values.

Args
mime_message The email.Message instance from which you want to copy information.

ALLOWED_EMPTY_PROPERTIES

{
 'amp_html',
 'body',
 'subject'
}

ALLOW_BLANK_EMAIL True
PROPERTIES

{
 'alternate_bodies',
 'amp_html',
 'attachments',
 'bcc',
 'body',
 'cc',
 'date',
 'html',
 'message_id',
 'reply_to',
 'sender',
 'subject',
 'to'
}