How to automate Dynamic Verification from Gmail

From: ‘XXXXX’
To: ‘XXXXXXXXXX’
When: 2023-10-07 11:20:29


G-672921 is your Google verification code.

Above is the Body of the email that I’m trying to get UiPath to locate, read and then extract the code after the G-. I’m currently stumped as to how to go about it.

Hi @Tzahiem_King

To extract the verification code from the email body using UiPath, you can use string manipulation techniques. Assuming the email body is stored in a variable called emailBody, you can follow these steps:

  1. Use Regular Expressions:
    You can use regular expressions to find and extract the verification code (G-XXXXXX) from the email body. Here’s an example of how to do it:

    System.Text.RegularExpressions.Regex.Match(emailBody, "G-\d+").Value
    

    This regular expression pattern searches for “G-” followed by one or more digits (\d+).

  2. Store the Extracted Code:
    Store the extracted verification code in a variable for further use. For example:

    Assign activity: verificationCode = System.Text.RegularExpressions.Regex.Match(emailBody, "G-\d+").Value
    
  3. Use the Verification Code:
    You can then use the verificationCode variable in your workflow as needed.

Thanks!!

@Tzahiem_King

Welcome to the community

  1. Use gmail activities and get the mails
  2. Use the following expression to get only the code

System.Text.RegularExpressions.Regex.Match(body,"(?<=G\-)\d+").Value

This gives you the code as string

Cheers

Hi @Tzahiem_King

Use Use the “Get IMAP Mail Messages” Activity
You can access the email’s body using the .Body property of the MailMessage object. Store the email body in a variable (emailBody).

Use a regular expression to search for the verification code pattern.

System.Text.RegularExpressions.Regex.Match(emailBody, "(?<=G-)\d+").Value

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.