If youāre testing a non-production system, you can divert your email to a 3rd party service that has an API, and use a request to extract and simulate the āemail confirmationā action.
There are several options, but I use a 3rd-party email service called MailTrap (https://mailtrap.io)
For example, this is the flow I use:
Register a new user POST /users with a known email
List emails via the MailTrap API
Use a Test Script to extract the link from the latest email and place it in an Environment Variable
Make a request to the extracted link in the Environment Variable
Login the user POST /auth/login
I made several assumptions about your use-case, but this is the most effective solution Iāve found thus far.
Iām also very curious to hear about any other solutions that people have come up with.
@parker937 Iām struggling to write the test script to extract the link from the latest email. Do you have an example of what you wrote? The url Iām trying to extract is something like https://company.com/confirm/:token thanks in advance for your help!
Itās been several months since Iāve used this script, but hereās what I had previously.
// Parse the response JSON
var response = JSON.parse(responseBody);
if (response[0] && response[0].html_body) {
let matches = /\?confirm_token\=(\w+)/g.exec(response[0].html_body);
postman.setEnvironmentVariable("confirm_token", matches[1]);
}
Hereās a possible modification to the regex for your example URL (this is untested): let matches = /\/confirm\/(\w+)/g.exec(html_body);
Since posting, the MailTrap API has deprecated the html_body field and now passes a reference URL in the html_path attribute. This will require a second API call, but the same pattern as before can be used.
Make an API Call to MailTrap to list emails
Store html_path to an environment variable
Make an API call the the URL from the previously store environment variable
Use a regex to parse the token from the expected URL
thank you so much for your help! Modified it a bit to work with what Iāve got but, for anyone else who has this issue, this is what worked for me
var data = JSON.parse(responseBody);
var emailContent = JSON.stringify(data[pm.environment.get("email")].html);
var confirmationLink = /\/confirm\/(\w+)/g.exec(emailContent);
postman.setEnvironmentVariable("confirmToken", confirmationLink[0]);
probably a better way to do this but it works so Iām happy
No, i did not figure it out how Mailgun and Postman work togheter. The issue was on our side because none of us (developers and testers) knew how this work.
A better explanation is needed, Maybe a video tutorial.
I can recommend MailSlurp for that use-case, see https://app.mailslurp.com. I will quickly explain how I use the MailSlurp API (https://api.mailslurp.com/swagger-ui.html#). I will register an email provided by MailSlurp in a random web portal. Every email has an inbox connected to it. After that I will call the /waitForLatestEmail endpoint from the MailSlurp API. The response is in this case the registration mail in JSON format. You can then e.g. extract the āverification tokenā from the response or check the email-sender, etcā¦
I think itās a great service to test mail delivery.