How to enter otp in a website which I receive in Gmail

Hello all

When I log in to a website due to 2fa it sends otp in Gmail. so how can I fetch only otp from email?
I have attached an image for reference

@Mozammil,

Get it by using Regex.

@Mozammil

get mail activity

then use string manipulation or regex on the body

cheers

but how can filter this email do you have any demo for that.

@Mozammil

use a subject line or from email

a part of subject line also can be used

one example depending on email you have diff options

cheers

Working
@Anil_G thankyou

1 Like

@Mozammil

Glad it helped

Cheers

Hi,

  • Retrieve the Email:
  • Use the Get IMAP Mail Messages or Get Outlook Mail Messages activity, depending on your email provider.
  • Set up the activity to fetch emails from your inbox. Use filters if necessary to retrieve only relevant emails (e.g., using a subject filter like “Your Copilot security code”).
  • Extract the OTP:
  • Loop through the retrieved emails and use the For Each activity to process each mail.
  • Use the MailMessage.Body property to get the email body text.
  • Use Regex to extract the OTP code. For example, if your OTP is always a 6-digit number, you can use the pattern \b\d{6}\b to match it.Example:
otpCode = System.Text.RegularExpressions.Regex.Match(mail.Body, "\b\d{6}\b").Value
  • Validate the OTP:
  • If multiple emails are received, you may want to sort emails by date and pick the latest one or add further conditions to ensure you’re extracting the correct OTP.
  • Use the OTP:
  • After extracting the OTP, you can use it in your workflow

Regards,
Kardelen