Email Content Analysis: An Inbound Parse Sample Application – Part 2

iStock_000011367808XSmallIn Part 2 of our series on Inbound Parsing sample applications, we’re examining a simple web application built with Node.js, MongoDB, WebSockets, and D3.js. Though aimed more at developers, this post also might serve to inspire some business use cases for SocketLabs’ Inbound Parse feature.

To start off, let’s take a peek at the front end of the application here. Send an email to [email protected] with a bunch of “hammer”, “wrench”, or other tool product keywords. The chart updates in real time, and behind the scenes the email is persisted to a queryable database. It may be a bit contrived, but imagine the real business uses this type of app could take on!

So how does this work?

At the most basic level, there are really only two requirements for your endpoint:

  1. Return the SocketLabs Inbound Parse Validation Code – When you enable Inbound Parsing on the appropriate configuration page for your SocketLabs’ Server, you’ll receive your Validation Code. We use this to verify that the endpoint to which we’re POSTing your emails is under your control – so we require that you return this validation code in the body of the response of every request to your endpoint. Most importantly, this is how we initially validate your endpoint and allow enabling of Inbound Parsing.
  2. Receive JSON messages in the HTTP POST request… and do something with them – See the documentation here for full details of the structure of the JSON message. Many of the fields are self-explanatory, and most web frameworks will be able to parse them into easy-to-work-with objects in the native language.

And that’s it! After you have those two parts in place, the rest is up to your own creativity in meeting business needs with this setup. In the sample app demonstrated here, we’ve done the following:

  • Used the Node.js built-in web server and JSON-parsing capabilities to easily receive and process the POSTed messages.
  • Inserted the JSON-formatted messages into MongoDB – which stores its content as JSON so it’s a seamless transition. These messages are then available in Mongo for subsequent querying at any time.
  • Run some quick analysis on the email content – in our case just count up keyword occurrences – and use WebSockets (via Node’s socket.io module) to push these counts in real-time to browser clients.
  • Use the D3 Javascript library to plot the results.

Pairing SocketLabs’ Inbound Parse feature with these technologies allows for some interesting and useful email-web apps. This demo is just a glimpse into the possibilities. The sample project is available here under the Node directory.