Identify usernames in email body


#1

Dear all

I have to identify a 8 character long usernames in a email body.
My idea is to parse the complete text (from an email body) and find all words that is 8 characters long and look them up in the user database.

My question: How to identify all words in a text which is 8 char long?

Remark: a username can be both letters and numbers eg: A1234567, Test1234, abcdefg1 or 1234567A etc.

Thanks!


#2

@robert.justesen, The best way is to use Regex

In Matches Activity,

Input - Your Email body which is a string
pattern - ([A-Z0-9a-z]{8})
Output - Save to a variable of type (Ienumerbale(of match))

Regardfs,
Dominic :slight_smile:


How to read a mail id from another mail
#3

Hi @robert.justesen,

@Dominic if you use regex sometime return false if mail length is small

For Example Mail id is strMail = a1c2v3@gmail.com
IntMailIdLength=strMail.Split("@"c)(0).ToString.Length

if condition IntMailIdLength<=8
Then
strUserName=strMail.Split("@“c)(0).ToString
else
strUserName=strMail.Split(”@"c)(0).Substring(0,7)

Regards,
Arivu


How to getmail id from mail body in gmail account?
#4

@arivu96, As robert requirement is to match from Mail Body not from Mail Id

@robert.justesen, Correct me if I am wrong .

Regards,
Dominic :slight_smile:


#5

Thanks for your reply’s

Yes - it is from the mail body and the username is not an e-mail

The Mail.Body could look something like this:

Dear Mr. Justesen
My old username for the Microsoft system is X1234567 and …
BR Justesen

The accepted result is:
Justesen
username
X1234567
Justesen

With the ([A-Z0-9a-z]{8}) I’m also getting Microsof as a result.


#6

Resolved it with a \b before and after:

Regex.Matches(Mail.Body,"\b([A-Z0-9a-z]{8})\b")

Thanks !!


How to read a mail id from another mail