How to check for email till email exists or by retrying?

Use Case: I have a 2 step login in which OTP is received via email. The OTP is received within 2-5 mins. I want to build the code as to check the email after every min till retry counts exist.

Can anyone please help?

If I correctly understand your question, I would create a loop with a counter and maxloop is e.g. 100 times(otherwise it will never stop). So inside the the loop you check the mails and if it is not found the counter will be increased by 1 and a delay of 60 seconds follows . If it is found you will set the counter to max +1 and the loop ends.