Handling email confirmation

Let say I have to test following scenario

  1. Register to the system
    User will receive register confirmation email

  2. User click on the register confirmation email

  3. Login to system from user name and password

In here I have 2 end points

POST Register and POST Login

but for the email confirmation part I do not have any end point

Since email confirmation is must to do before login Iā€™m blocked in the middleā€™
how can we accommodate this scenario using postmen?

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.

2 Likes

@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

Hope that helps!

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 :smiley:

Does anyone knows if there is a tutorial or course how to set up postman with Mailtrap or Mailgun and how to use it in real time.

Hey @Calibraticboy

You could use this for Mailgun.

https://www.mailgun.com/blog/together-at-last-postman-meets-mailgun

Select the ā€˜Run In Postmanā€™ button to import the collection locally.

The collection also contains the documentation needed for the different endpoints.

1 Like

Thanks for sharing. Will take a look at it.

1 Like

Hi there, I am actually the author of that blog post at Mailgun! Did you ever figure out how to get Mailgunā€™s APIs + Postman cooperating together?

Hi @mkane

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.

Best regard
CR

Hi All,

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.

Michael,

Do you have an updated collection for this? The collection on the shared link is not supported anymore on postman

Thanks