a dictionary with keys as strings. This should
contain bounce information, and the following keys are handled:
original-from
original-to
original-cc
original-bcc
original-subject
original-text
notification-from
notification-to
notification-cc
notification-bcc
notification-subject
notification-text
raw-message
For all keys except 'raw-message', the value can be anything.
The Bounce Notification object just assigns these values to the
original and notification properties of this instance,
which are dictionaries.
For example, original["to"] = post_vars.get("original-to")
The raw-message value is used to create an InboundEmailMessage
object. This value should be a valid input to the EmailMessage
constructor (inherited by 'InboundEmailMessage').
Flask- This is typically the flask.request.form field (if
the user wants to pass single (non-list) values for each key), or
'dict(flask.request.form.lists())' if the user wants to store a list for
each key (example use case is multiple to and cc recipients).
Webob- webob.Request.POST can be used for single values, and
webob.Request.POST.dict_of_lists() for multiple values.
Django- request.POST can be used for single values, and
dict(request.POST.lists()) can be used for multiple values.
# Add logic for what to do with the bounce notificationprint('Bounce original: %s',bounce_msg.original)print('Bounce notification: %s',bounce_msg.notification)# Return suitable responseresponse=http.HTTPStatus.OKstart_response(f'{response.value}{response.phrase}',[])return['success'.encode('utf-8')]
Args
environ
a WSGI dict describing the HTTP request (See PEP 333).
[[["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."],[[["\u003cp\u003eThis document describes the \u003ccode\u003eBounceNotification\u003c/code\u003e class, which is used to encapsulate bounce notifications received by an application, inheriting from \u003ccode\u003eexpected_type\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eBounceNotification\u003c/code\u003e object is initialized with a dictionary \u003ccode\u003epost_vars\u003c/code\u003e containing bounce information, including original and notification details of the email, as well as a raw message, and how to pass them using different frameworks is provided.\u003c/p\u003e\n"],["\u003cp\u003eThe object has attributes \u003ccode\u003enotification\u003c/code\u003e, \u003ccode\u003eoriginal\u003c/code\u003e, and \u003ccode\u003eoriginal_raw_message\u003c/code\u003e, which store the parsed data from \u003ccode\u003epost_vars\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe class method \u003ccode\u003efrom_environ\u003c/code\u003e allows the creation of a \u003ccode\u003eBounceNotification\u003c/code\u003e object directly from an HTTP request body, demonstrated with a WSGI example.\u003c/p\u003e\n"],["\u003cp\u003eThe keys of the \u003ccode\u003epost_vars\u003c/code\u003e dictionary include such items as \u003ccode\u003eoriginal-from\u003c/code\u003e and \u003ccode\u003enotification-to\u003c/code\u003e, and the \u003ccode\u003eraw-message\u003c/code\u003e key takes in a valid input to the EmailMessage constructor.\u003c/p\u003e\n"]]],[],null,["# google.appengine.api.mail.BounceNotification\n\n\u003cbr /\u003e\n\nEncapsulates a bounce notification received by the application.\n\nInherits From: [`expected_type`](../../../../google/appengine/api/validation/Validator/expected_type) \n\n google.appengine.api.mail.BounceNotification(\n post_vars: typing.Mapping[str, typing.Any]\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_environ`\n\n[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/mail.py#L1912-L1943) \n\n @classmethod\n from_environ(\n environ\n )\n\nTransforms the HTTP request body to a bounce notification object.\n\nExample(WSGI)::\n\ndef BounceReceiver(environ, start_response):\nbounce_msg = mail.BounceNotification.from_environ(environ) \n\n # Add logic for what to do with the bounce notification\n print('Bounce original: %s', bounce_msg.original)\n print('Bounce notification: %s', bounce_msg.notification)\n\n # Return suitable response\n response = http.HTTPStatus.OK\n start_response(f'{response.value} {response.phrase}', [])\n return ['success'.encode('utf-8')]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]