Email Testing in Postman: Wait for a Verification Email
Postman isn’t just for poking endpoints — with a collection and a few test scripts, you can automate a whole email-verification flow: create an inbox, trigger your app, wait for the email, and pull out the code. Here’s how, without leaving Postman.
Set up variables
You’ll call two APIs: your app (to trigger the email) and Devmailr (to create an inbox and read mail). Add collection/environment variables for the base URL devmailr_base = https://api.devmailr.app/api and your secret DEVMAILR_API_KEY.
Request 1 — Create an inbox
POST {{devmailr_base}}/mailboxes
Authorization: Bearer {{DEVMAILR_API_KEY}}
Content-Type: application/json
{ "prefix": "pm-{{$timestamp}}" }In the request’s Tests tab, save the new inbox for later requests:
const inbox = pm.response.json()
pm.collectionVariables.set('mailbox_id', inbox._id)
pm.collectionVariables.set('mailbox_address', inbox.address)Request 2 — Trigger your app
Send your app’s signup request to the disposable address (use the saved mailbox_addressvariable). Nothing special here — you’re just making your app email that address.
Request 3 — Wait for the email and grab the code
GET {{devmailr_base}}/mailboxes/{{mailbox_id}}/wait?has_code=true&timeout=60
Authorization: Bearer {{DEVMAILR_API_KEY}}const email = pm.response.json()
pm.test('email has a code', function () {
pm.expect(email.extractedCodes.length).to.be.above(0)
})
pm.collectionVariables.set('otp', email.extractedCodes[0])Mind the timeout: /wait long-polls up to 60s. Set Postman’s request timeout to 0 (no timeout) or above your wait timeout in Settings, so Postman doesn’t abort the call early.
Request 4 — Verify and clean up
Use the saved otp variable in your verify request, then DELETE {{devmailr_base}}/mailboxes/{{mailbox_id}} to clean up the inbox.
Run it in CI with Newman
Export the collection and run it headless with Newman (Postman’s CLI):
newman run email-flow.postman_collection.json \
--env-var "DEVMAILR_API_KEY=$DEVMAILR_API_KEY"Now the verification flow runs on every pipeline, no UI required.
Tips
- Use a dynamic variable in the prefix (a timestamp) so parallel runs don’t collide.
- Raise Postman’s request timeout above the wait timeout.
- For magic links, read
email.primaryLinkinstead of the code.
Related reading
Try it in two minutes
Create a disposable prefix@devmailr.app inbox over the API, send mail to it from your app, and read it in your tests. Free plan, no card required.