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 ...

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'.

from_environ

View source

Creates an email message by parsing the HTTP request body in environ.

Example (WSGI)::

def app(environ, start_response): mail_message = mail.InboundEmailMessage.from_environ(request.environ)

# Do something with the message
logging.info('Received greeting from %s: %s' % (mail_message.sender,
                                                  mail_message.body))
start_response("200 OK", [])
return “Success”

Args
environ a WSGI dict describing the HTTP request (See PEP 333).

Returns
An InboundEmailMessage object.

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'
}