Search code examples
exchangelib

Parsing XML returned by SendNotification in exchangelib


I'm working on a python project to process emails as they arrive in a Microsoft inbox. Specifically, I want to set up a push subscription, receive notifications when a new email hits the inbox, and then construct and send another email based on the body of the one just received.

I'm at a loss to understand where "response.data" comes from since I can't find a reference to it anywhere in the documentation. The comment says:

When the server sends a push notification, the POST data contains a 'SendNotification' XML document. You can use exchangelib in the callback URL implementation to parse this data:

And the code in the example is:

ws = SendNotification(protocol=a.protocol)
for notification in ws.parse(response.data):
    # ws.parse() returns Notification objects
    pass

Where might I find a reference to this response.data?

Thanks in advance.


Solution

  • response.data is just a placeholder for whatever your web server framework calls the request object. The above code snippet is meant to be used in the web server code that handles the push events that Exchange sends to the URL that you defined when you created the push notification.