

The request handler first fetches all subscriptions from the Datastore and then prints them in the page, together with a simple counter. GET requests to the app root url are used to list the subscriptions that have been collected. In case the request doesn't include the required field, the request handler will return a HTTP 400 response code, signaling the invalid request.
Mailist in gmail code#
This results in a HTTP 200 response code being sent back to Gmail to signal the successful request. The request handler simply checks that the required user_id is defined and then stores the subscription in the Datastore.

The SubscribeHandler class listens to bothPOST andGET requests sent to the app root url ( ).POST requests are used by Gmail to insert new subscriptions including theuser_id` parameter that corresponds to the user, as in the following example: Subscriptions = Subscription.all().fetch(1000)

# retrieve up to 1000 subscriptions from the Datastore Subscription = Subscription(user_id=user_id) # insert the subscription into the Datastore Collecting and listing subscriptionsĬopy the following code into a file named subscribe.py in the App Engine project folder: import webapp2Ĭlass SubscribeHandler(webapp2.RequestHandler): Then, it loads the email body from mail_template.html, replaces the confirm_url placeholder in it with the root url of the App Engine app ( ), and sends the email to the currently logged-in user as themselves. The EmailSender class requires the user to be logged-in so that their email address can be retrieved. Subject = 'Please confirm your subscription to Mailing-List XYZ', Put all of the files for your application in this directory.Ĭopy the following code to a file named app.yaml and replace the )
Mailist in gmail how to#
This guide assumes you have already installed the App Engine SDK and know how to create, run, and publish App Engine projects.įirst, create a directory for your project. This article shows how to build an App Engine app in Python that sends annotated emails to users asking to confirm a mailing list subscription directly from their inbox and collects the subscriptions in the Datastore.
