Integrating Emails into Kapow

Sending emails in Kapow is easy – just define your SMTP server, add a Send Email action – and you are set. But what about the opposite: what if you want your robots to work with incoming emails? It’s not longer as trivial as there is no single Import Email action on one hand (yet) – and on the other, emails themselves can be quite complex to handle. This post will focus on the former, more technical challenge: which options are on the table if you want to import emails? All options can be divided into two larger groups:

  1. Direct Access: this is where we will more or less – directly access messages via native protocols or file formats.
  2. Indirect Access: messages and relevant content will be retrieved using certain techniques and tools.

Let’s dive right into it:

Direct Access

Exchange Web Services (EWS)

If you’re running an Exchange Server, either On-Premise or via Cloud Services, today is your lucky day: you can just use SOAP web services to retrieve your messages and all relevant data (you could send and manipulate anything to be precise, contacts, calendar entries – you name it). The robot in the following screenshot does exactly that: first, it requests any object with items (messages) contained within. Then, it loops over all folders, picks the right one, and extracts relevant data (just the Subject, the Display To and Date Sent).

However, sometimes assisted entries will not work however – which means you have to build the SOAP request by hand (and nobody wants to do that). There is a great tool available that will save you many hours, the EWSEditor. Just connect to your Exchange server, move to the required object, and open the log – you can simply copy & paste the request over to the SOAP web service action in Kapow:

Third Party Products plus Web Services

Another option is to use third pary products to poll emails from your servers and expose the result via RESTful web service to Kapow. For example, you can use the Python library exchangelib to access your mailboxes, parse results and then expose them via a RESTful web service using frameworks such as Flask.

And if EWS isn’t an option, there are plenty of frameworks available for using IMAP or even POP3, if you dare.

Indirect Access

Web Automation

If there’s a web interface available, then Web Automation is probably the fastest way of integrating emails. This is also my preferred way of dealing with attachments: is there an Excel sheet or PDF that you need to process any further? Just go ahead, load it into an Excel or PDF variable, open it and scrape or modify it to your liking. I’ve seen robots that would scrape and Excel sheet and insert the content into a SQL table, essentially giving humans the most simplistic interface and way of inserting data into a table (I’m not saying it’s the best).

Here’s an example for Outlook Web Access. Note that I set the Kapow to emulate an iPhone as this automatically gets rid of the sidebar, and load times appear to be much quicker to me. Kapow can also easily handle infinite scrolling: as soon as we parsed all items on one single page (25), we just scroll to the last one – telling the server to load more. It’s really as simple as it sounds.

Desktop Automation

If there’s no web interface, fear not – Device Automation has you covered. With Kapow 10.3 we finally get for each loops within Device Automation steps, so the party there just never ends.

Conclusion and Outlook

There was a second question that has not yet been answered: why do you need to import emails in the first place? In the Age of the Customer, there are many other channels to consider with at least equal priority: social networks, chat bots, collaboration tools – just to name a few. Plus, emails are unstructured – sure, it’s easy if you know that there will be that Excel file attached that you will process in Kapow every single time; but in all other cases, they can be a challenge. How will you deal with the subject, the message body, and possible attachments? There are HTML messages versus plain text – can your robot handle this? And what about attachments – they can be quite unstructured themselves.

(Please note that a more native approach of integrating emails is on the roadmap for Kapow 10.4)