How to check whether a E-mail address is in correct format?

Hi Guys, I am facing a challenge now.

So here’s the thing. We have a user list with contacts such as phone number and e-mail. The robot need to send e-mail to each of the users on the list. But we found that when SMTP activity faces a wrong-format address, the robot stops automatically and doesn’t report the position or record. Is there any method that I can test the format of e-mail addresses on the list before sending mails?

Thanks and Happy New Year!

Aaron

You can IsMatch activity with a Regex expression to check the email is in valid format or not.

1 Like

You can also try creating a new MailAddress instance of your input e-mail. If the format is not correct it will fail and you will get an exception message.

Like so:
Create a variable of type System.Net.Mail.MailAddress.
Try giving it your input: myMailAddr = New MailAddress(addressToBeVerified)

br,
Topi

2 Likes

Hi @Topi,

It is not failing for the email address which contains slash “/”.
Eg. “s/kumari@uipath.com”

Email syntax accepts slash. For more info:

You can download Uipath.Email.Validation.Activities in manage packages created by saranpselvam. It contains Email validator activity that returns boolean type.

2 Likes

Use IsMatch to match Regular Expression pattern:

Tomatch email:

Pattern: \b[A-Z0-9._%±]+@[A-Z0-9.-]+.[A-Z]{2,}\b
Input: qsc.wdv@uipath.com
RegexOption: Select checkboxes based on requirement

1 Like

hello @Tuhin_Samanta the regex pattern you have provided has accepting given kind of email id’s also @Abc@gmail.com, which is a invalid one the correct pattern is "([\w.-]+)@([\w.-]+).([a-zA-Z]+) "

Thanks
Amal

1 Like

This is easy solution its working

Thanks
Chethan P

Ya, actually this approach is not 100%. The .NET mail address tries to find an address, even if it’s invalid.