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) => {
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => { rawData += chunk; });
res.on('end', () => {
resolve(rawData);
});
});
});
let webpageBody = '';
const runUntilReceived = () => {
checkMail()
.then(rawData => {
if (rawData.includes(expectedLink)) {
webpageBody = rawData;
console.log('Found expected link in webpage!', webpageBody);
return;
}
console.log('did not find email, checking ' + myEmail + ' again in 5 secs')
setTimeout(runUntilReceived, 5000);
});
};
runUntilReceived();
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.