nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
115 stars 52 forks source link

README Example #4, Sending an Email: Not Captured by a Stream #67

Open matthewbordas opened 6 years ago

matthewbordas commented 6 years ago

I've created a node server that uses the EWS Streaming API, via this library, to track Created and Modified events in a user's inbox, sentitems, and calendar folders. I'm writing unit/integration tests and running into a snag. I send an email programmatically (using the example from the README) and then I make sure its creation in the sentitems folder is tracked/captured by the stream. Unfortunately, this email creation isn't reported by the stream, although it shows up in the sentitems folder in an email client. Strangely, once I manually send an email through the email client, the stream reports the prior emails I sent programmatically, along with the new one just sent manually. Any ideas on what's going on? Is there a bug in the example code?

kcastrotech commented 6 years ago

Just for clarification, are you using the EWS Streaming or Push? We have an example of the Push listener but nothing for the EWS Streaming as that was breaking due to multiple envelopes being submitted from the server during the open streaming session (see #48). If you've got that working then I'd be curious how.

As for the EWS CreateItem not triggering an update, Node-EWS is just a wrapper for Node-SOAP which makes/receives SOAP messages with your EWS server. As such if you aren't seen a response from the server for the event then the problem is most likely on the server side or has something to do with the options in either the CreateItem or GetStreamingEvents requests.

I suggest you try using something like EWSEditor (https://ewseditor.codeplex.com/) to do some testing/debugging. With that you should be able use the "EWS Post" tool (under the "Tools" menu) to test out the raw SOAP calls and see the server responses. What I've done in the past is to open two instances of the "EWS Post" tool, initiate the streaming subscription request followed by the GetStreamingEvents (https://msdn.microsoft.com/en-us/library/office/gg236898(v=exchg.140).aspx) for all events in one instance to track the activity. (Note: After submitting the GetStreamingEvents call, you will need to wait the duration specified in the request before seeing all of the server responses in that window.) Then send the CreateItem call in the second instance and see what the server responds with. If the problem is duplicated outside of Node-EWS then it isn't a bug within Node-EWS but something to do with the EWS itself. But if the same SOAP requests work outside of Node-EWS then we can start to work the problem backwards from the server and figure out what's going on.

Hope this helps!

matthewbordas commented 6 years ago

I'm using EWS Streaming. I thought #48 revolved around being able to access the streaming requests as they come in as opposed to a breaking issue? I've gotten it to work through the GetStreamingEvents function. It throws an exception once the stream finishes, but I catch the exception and parse out the envelopes with the streamed notifications.

It might be an issue with the options in CreateItem, but I won't be able to know for sure until I test it with EWSEditor. I wasn't able to get it to run on my computer so I filed an issue on its repo. I can report more once I get it to work.

Thanks for the thorough response!

kcastrotech commented 6 years ago

Very clever! Why hadn't I thought to try that? LoL! Though ultimately with #48 I'm wanting to set up a streaming service with the max 30 minute open session and capture and process the server responses in real time.

kcastrotech commented 6 years ago

A compiled version of EWSEditor can be found here: https://ewseditor.codeplex.com/ Then you can just run the EWSEditor.exe

matthewbordas commented 6 years ago

Thanks for pointing me to the executable! I've tried using the EWS Editor to execute the flow of events that you outlined above. I can successfully initiate the streaming subscription to get a subscription ID, but whenever I try to make a GetStreamingEvents request it ends up failing and reporting an error (screenshot attached).

ewseditorgetstreamingeventserror

Any ideas why it might not be working? I've targeted Exchange 2010 SP1 and cloud-hosted Exchange on Office 365, but they both yield the same error.