4TestsEmail

Simple service for testing your applications' email flows with e2e tools, like Selenium, Cypress, Playwright, and so on.

Get Started

1. Register:

$ curl -L -X POST 'https://api.4tests.online/register' -H 'Content-Type: application/json' \
--data-raw '{ "name": "Your name", "username": "your.username", "password": "YOurP@$$wOrD" }'

2. Setup your QA environment application to our SMTP server:

email.server = "smtp.4tests.online"
email.port = 587 //STARTTLS
email.username = "your.username"
email.password = "YOurP@$$wOrD"

3. Run your application email flow, and check if an email was successfully sent: (Using Basic Auth)

$ curl -L -X GET 'https://api.4tests.online/emails/last?to=random-email@any-domain.com' \
-u 'your.username:YOurP@$$wOrD'

Or...

$ curl -L -X GET 'https://api.4tests.online/emails?subject=Subject' \
-u 'your.username:YOurP@$$wOrD'

And (For get full email data)

$ curl -L -X GET 'https://api.4tests.online/emails/{id}' \
-u 'your.username:YOurP@$$wOrD'

You going to have this as a return:

{
    "id": "63a8912da1393478274ea611",
    "date": "2023-01-01T12:00:00Z",
    "from": {
        "name": "From Name",
        "address": "from@email.com"
    },
    "to": [
        {
            "name": "",
            "address": "to1@email.com"
        }
    ],
    "cc": [],
    "cco": [],
    "subject": "Subject of email",
    "attachments": [
        {
            "fileName": "Document.pdf",
            "contentType": "application/pdf",
            "contentLength": 1000000
        }
    ],
    "contentType": "multipart/mixed",
    "html": "",
    "text": "Content as simple text"
}

4. Using some e2e tool and create the automation: (Example with Playwright)

test('register user and receive email', async ({ page }) => {
    // email is a random generated email address just for this test 
    const email = generateRandomEmail()
    
    // [...] skipping automation of register user flow here [...]

    await page.getByRole('button', { name: 'Register' }).click()
    
    const config = {
        message: 'make sure eventually register email arrive',
        timeout: 15000,
    }
    
    // This method repeatedly calls the API endpoint until a timeout of 15s or 200 response
    await expect.poll(async () => {
        const response = await page.request.get('https://api.4tests.online/emails/last', {
            headers: {
                Authorization: `Basic ${basicAuth}`
            },
            params: {
                to: email
            }
        })
        return response.status()
    }, config).toBe(200)
})

Considerations