google.appengine.api.mail.EmailMessage

Main interface to the Mail API service.

Inherits From: expected_type

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()

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.
content_type = 'text'       # Matches text of any kind.

Yields
A (content_type, payload) tuple for HTML and body 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

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

View source

Copies information for recipients from a MIME message.

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

ALLOWED_EMPTY_PROPERTIES

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

PROPERTIES

{
 'amp_html',
 'attachments',
 'bcc',
 'body',
 'cc',
 'headers',
 'html',
 'reply_to',
 'sender',
 'subject',
 'to'
}