Many times I’ve had to sweep an inbox and do something with the email. Typically the easiest way is to use IMAP, but our corporate email server has IMAP disabled.
Fortunately 2007 Microsoft Exchange has had a rich web service interface so I wanted to give that a try.
One of the main patterns used is to read an email and then move it to something like an ‘archive’ or ‘error’ directory. Exchange supports arbitrary message properties such as ‘category’ and even custom properties, so adding a category tag of “processed” seems like a good idea. I wanted to experiment a bit.
Some googling turned up a java API and seems ‘lightly’ supported. I had little luck finding any examples for just reading email.
I decided to check out the .NET library to see if that would shed some light on how to use the Java API – and it did.
and found the 2 APIs are very similar. By writing some samples in c# I was able to quickly port them into Java and something like this should work for you.
You do have to download the Microsoft .jar and a few dependencies to get this working. I’m posting this because I could not find this type of simple example.
tip: If you are unsure of the API domain endpoint look for the wsdl at https://EXCHANGE_API_DOMAIN/EWS/Services.wsdl
This post is for people who have started learning about hypermedia and feel that it over complicates the elegance of REST. When I started hearing about hypermedia I felt it was adding architecture acrobatics for the sake of buzzword enhancement. After having applied these techniques in a few places not only have a drunk the cool aid, I’ve setup a stand beside my desk. I look back and try to understand where my initial negative reaction came from. I realized that many of the examples were trivial and did not demonstrate the reality of what hypermedia brings to the table.
The main epiphany I’d like to share is that REST has proven itself as the best way to take an ORM focused approach to an API and Hypermedia is proving itself as the best way to take a business process approach to an API.
A key aspect of Hypermedia that I don’t see used often enough is the notion of a template. The template portion of the spec calls for the API to send down to the client the parameters necessary to call the API itself. This notion is akin to how you load a web page with a blank form and then submit the form directly. You don’t post to twitter by typing a bunch of stuff into the url, you load twitter first and then fill in a textarea.
Essentially in my early experiments I was writing XML api payloads where the template portion was basically an HTML form that the client could decompose and render. The problem that I felt was that I was basically writing a full old school web application that happened to send XML rather than HTML back to the client. Then my client had extra complexity in parsing the XML and implementing all the UX rules to get the client looking and feeling right. I also had to build 2 webapps that both were basically doing the same thing, view, validation and calling a service.
Now lets take a look at doing this for real using AngularJS, JSON and a deadline.