I'm testing an Email system where I would test a set of received emails to see if the received emails actually displayed as expected.

This is done for each release of the system. So basically I want to automate this process. When the emails are received, the automated testing process should open each email through the web browser (because emails are typically sent to Gmail account) and validate them.

Also in the manual testing process, each email is identified by a string in the email content.

  • 2
    Hi, Sinaru, when you say "displayed as expected" do you mean that they contain all the text you expect, or that they contain the text and markup you're expecting? If you're wanting to validate text, that's fairly easy. Validating layout, markup and display is something that's often better handled manually. – Kate Paulk Aug 15 '13 at 11:35
  • 1
    If you just want to know whether the email arrives in your Inbox or gets stuck in your Spam folder, there is a simpler way to do that. – user246 Aug 15 '13 at 12:47
  • When you say, you are testing an Email system, are you testing the sending part of the system (MTA) or are you using a service and want to test that it sends your emails correctly? – Suchit Parikh Aug 15 '13 at 16:38

Since everything is web based, can't you just use a strait up browser automation framework like Selenium?

  • Do what you need to do in your system to trigger the sending of the email.
  • Log into Gmail
  • Check if the email is there
  • Take a screenshot (if needed)

Anything you can do as a user (besides thinking and seeing if visual layout is nice) you can more or less do in some flavor of Selenium.


My bad I misread the question. You can just fire up a selenium browser in a process that sits in gmail in HTML Only mode, checks for new messages every X seconds (by pulling for the elments), and then opens the emails and runs whatever test you want to do on the email.

  • Gmail in html mode is easy mode for automating email-related tasks. You can record a sample test in selenium and edit it to meet your needs; might be up and running in as little as a few hours. – Lucas Schwarz Aug 26 '13 at 22:43

Disclaimer - I work for the company that made a solution for this scenario.

mailosaur.com gives you unlimited test email addresses and a fake SMTP server. Each time an email is received, it will parse the html and extract all the links, optionally visit all these links and store the responses etc...

There's a REST API which allows you to access any property of your email for validaton. We have bindings for Java, .NET and Ruby to make your life as easy as possible.


You could use the GMail Google API. This is working fine and sort the problem that was similar to what you have described. You just need to create an account and enable the api for it. Please refer to the link below for the complete guide:


  • Please post answer and not just a link. – Prome Dec 4 '19 at 9:13

There are QA email testing websites with APIs to make this much easier than using gmail.

Using mailsac.com and Node.js, something like this would work: (warning- mail is public when free)

Say you want to detect an email with the following signup link:

const expectedLink = "https://www.example.com/signup/asdf-asdf-asdf";

Generate a random email address:

const myEmail = 'sinaru-' + Math.random().toString(36).substring(2) + "@mailsac.com";
// example:
// sinaru-ovs6qeq508@mailsac.com

Now send your email to the random address, from the application.

Then wait for mail to be received, checking every 5 seconds:

const https = require('https');

const checkMail = () => new Promise(resolve => {
  https.get('https://mailsac.com/inbox/' + myEmail, (res) => {
    let rawData = '';
    res.on('data', (chunk) => { rawData += chunk; });
    res.on('end', () => {

let webpageBody = '';
const runUntilReceived = () => {
    .then(rawData => {
      if (rawData.includes(expectedLink)) {
        webpageBody = rawData;
        console.log('Found expected link in webpage!', webpageBody);
      console.log('did not find email, checking ' + myEmail + ' again in 5 secs')
      setTimeout(runUntilReceived, 5000);


Of course they have an API which makes this easier to do, which it requires signup and an API key. This is a quick and dirty way to check whether the link was in the email body and is printed on the webpage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.