Get specific information from mail body

Hi everyone,

I have extracted an email from my mailbox. In this email there is structured data (name, adress, postal code, etc.). I want to extract this data from the email, but I can’t figure out how to do it. Example of the email:


Some random text.

Name: great name
Adres: streetname 123
City: best city
Postal code: 1234 XG

Kind regards,
a person.

I want to save the name in a variable str_name, adres in str_adress, city in str_city, etc. Can someone explain to me how to do this? Do note, the name can exist out of 2, 3, 4 or more words, same of the city and adres. Length of these values is unknown up front.

Thanks in advance!


You can get the whole message string and split it by newline character so you get the array of each line as string… Now check either : exist or not - if yes split it using : and put the result in dictionary… Now you can access each detail using dictionary.

Note: if complete name/dress found in same line means use this, else better to use regEx. (To use regEx the input format should be same as this everytime. I.e address comes after name always or postal comes after City always )


Thank you, but I am not sure what you mean. Can you send me some example code? For the assign?
thanks in advance!


You can assign for Address string variable as

txtData.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries).Where(Function(x) x.Contains(“adres” )).ToArray(0).ToString.Split(":"c)(1).ToString

this gives the address, for name replace address to name from the above query.
Make sure : your complete input is in string txtData