Stay organized with collections Save and categorize content based on your preferences.
google.appengine.api.mail module SummarySends email on behalf of the application.
This module provides functions for application developers to provide email services for their applications. The module also provides a few utility methods.
ContentsBases: google.appengine.api.mail._EmailMessageBase
Interface that sends email messages to all administrators via the Mail API.
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()
Bases: object
Attachment object.
An Attachment object is largely interchangeable with a (filename, payload)
tuple.
The behavior is a bit asymmetric with respect to unpacking and equality comparison. An Attachment object without a content ID will be equivalent to a (filename, payload)
tuple. An Attachment with a content ID will unpack to a (filename, payload)
tuple, but will compare unequally to that tuple.
Thus, the following comparison will succeed:
attachment = mail.Attachment('foo.jpg', 'data')
filename, payload = attachment
attachment == filename, payload
…while the following will fail:
attachment = mail.Attachment('foo.jpg', 'data', content_id='<foo>')
filename, payload = attachment
attachment == filename, payload
The following comparison will pass:
attachment = mail.Attachment('foo.jpg', 'data', content_id='<foo>')
attachment == (attachment.filename,
attachment.payload,
attachment.content_id)
The name of the attachment.
The attachment data.
Optional; the content ID for this attachment. Keyword only.
Verifies whether an email is valid.
Parametersemail_address – Email address to check.
field – Field to check.
InvalidEmailError – If email_address
is invalid.
Bases: google.appengine.api.mail._EmailMessageBase
Main interface to the Mail API service.
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()
Ensures that recipients have been specified.
Performs more conversion of recipient fields to the protocol buffer.
ReturnsThe MailMessage
protocol version of the mail message, including sender fields.
Provides additional checks to ensure that recipients have been specified.
RaisesMissingRecipientError – If no recipients are specified in ‘To’, ‘Cc’, or ‘Bcc’.
Copies information for recipients from a MIME message.
Parametersmime_message – The email.Message
instance from which to copy information.
Bases: object
Wrapper for a payload that contains encoding information.
When an email is received, it is usually encoded using a certain character set, then possibly further encoded using a transfer encoding in that character set. Most of the time, it is possible to decode the encoded payload as-is; however, in the case where it is not, the encoded payload and the original encoding information must be preserved.
The original encoded payload.
The character set of the encoded payload. To specify that you want to use the default character set, set this argument to None
.
The transfer encoding of the encoded payload. To specify that you do not want the content to be encoded, set this argument to None
.
Copies the contents of a message to a MIME message payload.
If no content transfer encoding is specified and the character set does not equal the overall message encoding, the payload will be base64-encoded.
Parametersmime_message – Message instance that will receive the new payload.
Attempts to decode the encoded data.
This function attempts to use Python’s codec library to decode the payload. All exceptions are passed back to the caller.
ReturnsThe binary or Unicode version of the payload content.
Converts a message to a MIME message.
ReturnsThe MIME message instance of the payload.
Bases: google.appengine.api.mail.EmailMessage
Receives a parsed email as it is recevied from an external source.
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 ...
Iterates over all bodies.
Parameterscontent_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 all bodies of a message, including the body, HTML, and all alternate_bodies
, in that order.
Converts a message to a MIME message.
This function adds additional headers from the inbound email.
ReturnsThe MIME message instance of a payload.
Updates the values of a MIME message.
This function copies over date values.
Parametersmime_message – The email.Message
instance from which you want to copy information.
Determines the reason why an email is invalid.
Parametersemail_address – Email address to check.
field – Field that is invalid.
A string that indicates the reason why an email is invalid; otherwise returns None
.
Determines whether an email address is invalid.
Parametersemail_address – Email address to check.
ReturnsTrue
if the specified email address is valid; otherwise returns False
.
Generates a MIMEMultipart
message from a MailMessage
protocol buffer.
This function generates a complete MIMEMultipart
email object from a MailMessage
protocol buffer. The body fields are sent as individual alternatives if they are both present; otherwise, only one body part is sent.
Multiple entry email fields, such as ‘To’, ‘Cc’, and ‘Bcc’ are converted to a list of comma-separated email addresses.
Parametersprotocol_message – Message protocol buffer to convert to a MIMEMultipart
message.
A MIMEMultipart
message that represents the provided MailMessage
.
InvalidAttachmentTypeError – If the file type of the attachment is invalid.
Sends mail on behalf of the application.
Parameterssender – Sender email address as it appears in the ‘From’ email line.
to – List of one or more ‘To’ addresses.
subject – Message subject string.
body – Plain-text body.
make_sync_call – Function used to make a sync call to an API proxy.
**kw – Keyword arguments that are compatible with the EmailMessage
keyword based constructor.
InvalidEmailError – If an invalid email address was specified.
Sends email to administrators on behalf of the application.
Parameterssender – Sender email address as it appears in the ‘From’ email line.
subject – Message subject string.
body – Plain-text body.
make_sync_call – Function used to make a sync call to an API proxy.
**kw – Keyword arguments that are compatible with the EmailMessage
keyword based constructor.
InvalidEmailError – If an invalid email address was specified.
Verifies whether an email is valid.
Parametersemail_address – Email address to check.
field – Field to check.
InvalidEmailError – If email_address
is invalid.
Determines the reason why an email is invalid.
Parametersemail_address – Email address to check.
field – Field that is invalid.
A string that indicates the reason why an email is invalid; otherwise returns None
.
Returns whether a string is in ASCII.
Determines whether an email address is invalid.
Parametersemail_address – Email address to check.
ReturnsTrue
if the specified email address is valid; otherwise returns False
.
Generates a MIMEMultipart
message from a MailMessage
protocol buffer.
This function generates a complete MIMEMultipart
email object from a MailMessage
protocol buffer. The body fields are sent as individual alternatives if they are both present; otherwise, only one body part is sent.
Multiple entry email fields, such as ‘To’, ‘Cc’, and ‘Bcc’ are converted to a list of comma-separated email addresses.
Parametersprotocol_message – Message protocol buffer to convert to a MIMEMultipart
message.
A MIMEMultipart
message that represents the provided MailMessage
.
InvalidAttachmentTypeError – If the file type of the attachment is invalid.
Sends mail on behalf of the application.
Parameterssender – Sender email address as it appears in the ‘From’ email line.
to – List of one or more ‘To’ addresses.
subject – Message subject string.
body – Plain-text body.
make_sync_call – Function used to make a sync call to an API proxy.
**kw – Keyword arguments that are compatible with the EmailMessage
keyword based constructor.
InvalidEmailError – If an invalid email address was specified.
Sends email to administrators on behalf of the application.
Parameterssender – Sender email address as it appears in the ‘From’ email line.
subject – Message subject string.
body – Plain-text body.
make_sync_call – Function used to make a sync call to an API proxy.
**kw – Keyword arguments that are compatible with the EmailMessage
keyword based constructor.
InvalidEmailError – If an invalid email address was specified.
A decorator that decorates a decorator’s wrapper.
This decorator makes it easier to debug code that is heavily decorated.
Parameterswrapped – The decorated function that you are trying to debug.
ReturnsA function with __name__
, __doc__
, and ___dict__
remapped to the respective versions of the wrapped function to make debugging easier.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["This module facilitates sending emails from applications, offering classes and functions for composing and sending both standard and administrative email messages."],["The `EmailMessage` and `AdminEmailMessage` classes allow for programmatic email creation with options to set sender, recipient, subject, and body, and the messages can be built within the constructor or mutably."],["The `Attachment` class manages file attachments with optional content IDs, while also behaving similarly to a `(filename, payload)` tuple for data handling."],["The module includes functions to validate email addresses (`CheckEmailValid`, `IsEmailValid`) and to determine the reason for invalid emails (`InvalidEmailReason`), as well as validating headers."],["`InboundEmailMessage` allows you to receive and parse incoming emails, handle different content types, and manage various message attributes like date, sender, and attachments."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4