Set up
Install the proxymail-qa package and put an API key in PROXYMAIL_QA_API_KEY in the environment Cypress runs in. The Free plan is enough.
npm install --save-dev proxymail-qa
Register the tasks
import { defineConfig } from 'cypress';
import { ProxyMailQA } from 'proxymail-qa';
export default defineConfig({
e2e: {
setupNodeEvents(on) {
const qa = new ProxyMailQA(); // reads PROXYMAIL_QA_API_KEY
on('task', {
createAddress: () => qa.createAddress({ persona: true }),
waitForLink: ({ address, since }: { address: string; since: string }) => qa.waitForLink(address, { type: 'verify', since }),
waitForCode: ({ address, since }: { address: string; since: string }) => qa.waitForCode(address, { since }),
deleteAddress: (address: string) => qa.deleteAddress(address).then(() => null),
});
},
},
});
The test
it('verifies the email', () => {
cy.task('createAddress').then(({ address }) => {
const since = new Date().toISOString();
cy.visit('/signup');
cy.get('[name=email]').type(address);
cy.contains('Sign up').click();
cy.task('waitForLink', { address, since }, { timeout: 35000 }).then(({ value }) => cy.visit(value));
cy.task('deleteAddress', address);
});
});
For a code, call the waitForCode task the same way and type its value into the form. since makes the wait ignore anything sent before the form was submitted, so a retried test never reads an old email. Match the selectors and routes to your app.
Check the email, not just the link
Add tasks for the checks you want, such as one verification email rather than two, or the link going to staging:
countEmails: ({ address, since }: { address: string; since: string }) => qa.countEmails(address, { since, type: 'link' }),
checkEmail: ({ address, since }: { address: string; since: string }) => qa.checkEmail(address, { since, type: 'link', expectHost: 'staging.example.com' }),
checkEmail returns verdicts on SPF, DKIM and DMARC, links to localhost or plain http, where the link goes and more, never the email itself; assert that its failed list is empty.
Run it in CI
Store the key as a CI secret named PROXYMAIL_QA_API_KEY. In GitHub Actions, the Proxy Mail QA action also posts a report of the run’s emails on the pull request: which arrived, how fast, and which never came.
- uses: aaquib90/proxymail-qa-action@v1
with:
api-key: ${{ secrets.PROXYMAIL_QA_API_KEY }}
- run: npx cypress run
env:
PROXYMAIL_QA_API_KEY: ${{ secrets.PROXYMAIL_QA_API_KEY }}
More in the Cypress docs, Node.js client and Running in CI.