Hello community. I have a case to develop on UI Path as part of a business project.
I need to search for certain words in the body or subject of an email. So I use REGEX to filter the words to search.
I tried with Outlook Mail Message trigger but I can’t put my result in a variable. I also used foreach, I get the subject and body fine using item.ToString. I would like to assign these to a variable in order to retrieve my result.
As a beginner I would like to know the best way to retrieve information in variables.
Thank you beforehand
Hi @DimitriLYR
Welcome to forum
Regarding your question.
You need to filter only the mails which had certain words in subject and body, right?
Thanks & Regards,
Nived N
No, I recover all unread emails from a folder.
On these unread emails, I have to find “keywords” in the subject and/or body (Names of suppliers). Once the correspondence is made, I download the attachment (Invoice) to put it in the associated file (Supplier file)
Ok so after extracting the the required mails, u need to find the specific words, and then if the specific word is found, u had to download the attachment and save in the specific folder corresponding to the keyword/supplier , right ?
Hi @DimitriLYR,
I hope I understood your question correctly. I have tested and managed to assign the value of the Mail Message Body to a variable and then write it to the output pane. Please see the attached picture.
Regards,
JM

1 Like
@DimitriLYR
Great,
So the approach u had to follow is :
-
Extract all the unread emails using get emails from outlook activity and store in arrEmail variable.
-
Now loop through each mail in arrEmail using for each loop,
inside the loop do the following:
assuming that u had supplier names stored somewhere (let’s say u had stored in excel file and u had read the excel and store in dt1 datatable variable)
Now u can use the below code to get the name of supplier which is present in that email
supplier_name= (From row in dt1.AsEnumerable()
Where System.Text.RegularExpressions.Regex.IsMatch(item.Body.ToString,“\s+”+row(0).ToString.Trim+“\s+”)=True
Select row(0).ToString).ToArray()
Here i am assuming that excel file dt1 is having one column for supplier names.
Now download the attachment from that email using download attachment activity and store in specific folder location with the help of supplier_name array varaible
eg: supplier_name={“ABC”}, we had got it from above code
Now ABC is supplier name present in email, now in download attachment activity, we will specify the path as "C:\Users.…+supplier(0).ToString
Now the attachment will save to ABC folder
Hope this help you to get a clear picture
Thanks & Regards,
Nived N
1 Like
Hi, thanks for your answer
Where did you declare item? I have this error:
MailMessage.Item(0).Body.ToString() ‘item’ is not a member of System.Net.MailMessage
@DimitriLYR
Try
MailMessage.ElementAt(0).Body.ToString()
This issue appears since that code is Visual Basic, and your process is created with C#.
You can use:
MailMessage[0].Body.ToString()
1 Like
Thank for your answer
I’ll try, I’m still a beginner on UI Path but thank you for all this information
1 Like
Good
Let me know if you had any questions
Happy to help

1 Like
I have “expected end of expression” this time i don’t understand i’m trying to experiment
Could you share the screenshot pls?

Here is what I had tried. A foreach with each email, I pass it in REGEX to retrieve the keywords, and then a foreach for the retrieved words.
Please check the property pane for the “Get Outlook Mail Message” activity. You must have ‘Set Var: MailMessage’ as output.
If that does not work, please hover over the error and show the error message.
@DimitriLYR Is the MailMessageBody variable declared as a String?
Hello,joergen I succeeded with your explanations, thank you very much!
@Rahul_Unnikrishnan Hello, I succeeded with your explanations, thank you very much!
1 Like