A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/appengine/docs/legacy/standard/python/mail/receiving-mail-with-mail-api below:

Receiving Email | App Engine standard environment for Python 2

Receiving Email

Stay organized with collections Save and categorize content based on your preferences.

Email messages sent to your app are implemented as HTTP requests containing MIME data. To process incoming email messages, you associate email addresses with script handlers in your app configuration, then include the handlers in your app's code.

This page describes how to use the legacy bundled services and APIs. This API can only run in first-generation runtimes in the App Engine standard environment. If you are updating to the App Engine Python 3 runtime, refer to the migration guide to learn about your migration options for legacy bundled services.

Incoming email generates HTTP requests, which are passed to the appropriate scripts. The scripts that handle the incoming email must reside in your default service.

For more information on the Mail service, see the Mail API Overview.

Configuring your application to receive email

When you create a new app, incoming email is disabled by default. To enable the incoming email, you must modify your app.yaml file in your default service.

  1. Add an inbound_services section that enables the incoming email service. For example:

    If you don't enable incoming email by including this section in your configuration file, then incoming email is disabled, and email messages sent to the app are ignored.

  2. Add mappings that associate URL-mapped email addresses with script handlers.

    For the default service, the email address for receiving email has the following format:

    [STRING]@[Google Cloud project ID].appspotmail.com
    

    For non-default services, the email address has the following format:

    [STRING]@[servicename]-dot-[Google Cloud project ID].appspotmail.com
    

    Email messages are sent to your app as HTTP POST requests using the following URL, where [ADDRESS] is a full email address, including domain name:

    /_ah/mail/[ADDRESS]
    

    To handle incoming email in your app, map email URLs to handlers in the app.yaml file:

    In the above example, /_ah/mail/.+ matches all email addressed to the app. If you prefer, you can set up multiple handlers for different email addresses, as in the following example:

    URLs of incoming email messages are matched to this list from first to last, so if an email message URL matches more than one pattern, the first matching handler will be the one executed. This allows you to include a "catchall" handler as the last mapping. The handlers run in the default module (or application version).

Handling incoming email

The Python SDK defines InboundMailHandler, a webapp class for handling incoming email. InboundMailHandler is in the google.appengine.ext.webapp.mail_handlers package.

To use InboundMailHandler:

  1. Create a subclass for InboundMailHandler and override the receive() method.
  2. Call the receive() method with an argument of class InboundEmailMessage, defined by the Python SDK.

For example, you can create an instance of InboundEmailMessage like this:

Note: Even if you are using the webapp2 framework, you still need to use the InboundMailHandler class provided by the old webapp framework. This handler is specific to the App Engine mail service, whereas webapp2 is provided by a third party.

InboundMailHandler contains a mapping() convenience class method that returns a pair matching all incoming email addresses to the mail handler and of course you can call it on any subclass of InboundMailHandler you code:

The InboundEmailMessage object (mail_message in this example) contains the email message. Its bodies() method returns the bodies within the message. If you call bodies() without arguments, it returns an iterator that yields HTML bodies first, then plain text bodies. If you want just HTML or just plain text, you can pass an argument to bodies():

The InboundEmailMessage object includes attributes to access other message fields:

Simulating incoming messages with the local development server

Once you set up your app to handle incoming email, you can use the development server console to simulate incoming email messages:

  1. Access the development server as an administrator by going to http://localhost:8080/console and selecting Sign in as administrator.
  2. In the development server, click Inbound Mail in the navigation.
  3. Fill out the form that appears, and click Send Email.

    To learn more, including how to get the development server running, see the Python Development Server.

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-08-07 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-08-07 UTC."],[[["Incoming emails to the app are processed as HTTP requests with MIME data, requiring configuration to associate email addresses with specific script handlers."],["To enable incoming email, the `inbound_services` section with the `- mail` parameter must be added to the `app.yaml` file in the default service."],["Email URLs, formatted as `/_ah/mail/[ADDRESS]`, must be mapped to handlers in the `app.yaml` file to route incoming emails to the correct script."],["The `InboundMailHandler` class, which must be subclassed, should be used to manage incoming emails, and its `receive()` method should be overridden to process email messages."],["The development server allows simulating incoming emails for testing purposes through its console, which can be used to test the email handlers."]]],[]]


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