Python 3.10 is now available in preview.


Encapsulates a bounce notification received by the application.

Inherits From: expected_type

post_vars 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.






View source

Transforms the HTTP request body to a bounce notification object.


def BounceReceiver(environ, start_response): bounce_msg = mail.BounceNotification.from_environ(environ)

# Add logic for what to do with the bounce notification
print('Bounce original: %s', bounce_msg.original)
print('Bounce notification: %s', bounce_msg.notification)

# Return suitable response
response = http.HTTPStatus.OK
start_response(f'{response.value} {response.phrase}', [])
return ['success'.encode('utf-8')]

environ a WSGI dict describing the HTTP request (See PEP 333).

A BounceNotification object.