How to extract Verification Code from Outlook(just numbers)

Hello ,

How do we get the verifcation copde from Outlook when the body looks like below:


FYI: The code is dynamic in the length. Right now it’s 6 but might increase in future.

Thanks in advance :slight_smile:

Hi @ayushi_jain3

Write the body into text file. Read the text file and store the output in a variable and after that you can the extract the verification code using Regex expression and store that in a variable and use that variable in the further workflow.

Hope it helps!!

Hey, thanks for the reply. Could you please help with the regex expression. And where to use that like in which activity. Sorry I am kind of new to this.

Thanks !

Hi @ayushi_jain3

See, if you’re able to get the mail body in a variable.
You can use a Split function in an assign activity.

Create a variable verCode of type String.
In an assign activity use the below:

verCode = MailBody.toLower.Split({“verification code”},StringSplitOptions.None)(1).Trim.Split({“this code”},StringSplitOptions.None)(0).Trim

This should give you the dynamic verification codes being generated and sent on mail.



Send me the sample text after extraction of the the mail by using below syntax:
I will help you out with regex.


Hi @adiijaiin ,

It is giving " index out of bound array" error at second assign activity.

hi @ayushi_jain3
You see that we have used a toLower function hence you need to pass verification code and this code inside the parenthesis.

@adiijaiin , Thanks. It worked

1 Like

You are most welcome.

Thanks for marking the solution. :slight_smile:

Happy Automation!

1 Like

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