Saturday, September 6, 2014

MailCatcher REST client for emails testing

Sometimes it's important to verify emails content while web applications testing, or retrieve it to achieve some high level goals, e.g. password reset scenario. Besides that, we also need to keep in mind that customers shouldn't be spammed with test emails.

In this article we'll look at MailCatcher (MC) tool  - very simple SMTP server that is quite good for emails testing. Its key advantages are:
  • not spamming real users (it catches emails, preventing further sending to recipients list);
  • provides REST APIs for retrieving / deleting emails;
  • allows to read emails in json, html, plain text + full source;
  • has web UI;
  • cross-platform.
Note: you must install Ruby and SDK before setting up MC.
After MC installation, you'll be able to call mailcatcher from command line. It also has additional arguments, e.g. if you need to set custom ip or port:


Now we can open its web UI for accessing caught emails info:


So what's next? As I've mentioned above, MC provides some useful REST APIs for retrieving and deleting caught messages. It means that we can easily implement a simple REST client (e.g. via Jersey) for further content testing. Let's look at emails getting / deleting APIs:


You can find a full source code with some basic examples on GitHub.

No comments:

Post a Comment