How to apply multiple subject filters in get outlook mail message or for each email?

Hi Everyone,

I would like to ask a question " how to apply multiple subject filters in get outlook mail message or for each email?
My requirement is 1. I need to add 15 filters based on subject lines (all the data maintained in an excel file).
2. Bot should be able to read the mail from inbox as per given subject lines and then it will check the subjects in the excel file and if the same subject lines are present in the file then it will raise a ticket on an inhouse tool (as per set parameters).

I have tried this however I did not get the correct solution.

Any suggestions would be appreciated.

Best Regards,
Preety

Hi

Welcome to UiPath forum

Hope the below steps would help you resolve this

1.read the excel file with that column having all the subjective that needs to be validated using READ RANGE activity and get the output as a datatable named dt

  1. Then convert that one column from datatable as a array of value using this expression in assign activity

arr_subjectlines = yourdatatablename.AsEnumerable().Select(Function (a) a.Field(of string)(“yourcolumnname”).ToString).ToArray()

Where arr_subjectlines is a variable or type array of string

  1. Now get the output from get outlook mail as mailmessages

  2. Use a FOR EACH loop and pass the above mailmessage as input and change type argument as System.Mail.Mailmessage

  3. Inside the loop use a IF condition like this

arr_subjectlines.Contains(item.Subject)

If true it goes to then or else block

Cheers @TIN_RPA

Use and/or logic to make it all one filter, for example…

subject contains value1 or subject contains value2 or subject contains value3

Step 1: Read the subject filters from your Excel file into a collection in datatable

Step 2: Use a “For Each” loop through the collection of subject lines obtained from the Excel file.

Step 3: Inside the loop, use the “Get Outlook Mail Message” activity to retrieve emails from your inbox. In the filter options for this activity, use the current subject line as filter from Excel file.

Step 4: For each retrieved email within the loop, you can compare its subject with the subject line. If there’s a match, you can proceed to raise a ticket.

Hi @Palaniyappan,

Thank you very much for the solution. It really worked to get multiple subject filters as per the set inputs. However bot is getting failed while comparing between the subject line (which come over Outlook email) and excel file subject lines (which I have mentioned in the sheet) as subject length is not fixed.
For Instances-

Subjects lines which come over outlook email-

1.[External] Event ID : #44987340 | Application Name :PMDL Online check Web16 | Level 1: Error On Contact And Other Details Page : 02-Oct-2023 21:09:39

2.[External] Event ID : #44017654 | Application Name : PMDL New check Application | Level 1: Error On Contact And Other Details Page : 02-Oct-2023 21:09:39

  1. [External] Event ID : #44879425 | Application Name : PMDL_Helpdesk_Verfication_File_Based | Level 1: Error On Contact And Other Details Page : 02-Oct-2023 21:09:39

  2. [External] Event ID : #44873456 | Application Name : NALK Help desk mip 101 298 14 291 APPLICATION | Level 1: Error On Contact And Other Details Page : 02-Oct-2023 21:09:39

Subject lines which I have mentioned in excel sheet-

  1. PMDL Online check Web16
  2. PMDL New check Application
  3. PMDL_Helpdesk_Verfication_File_Based
  4. NALK Help desk mip 101 298 14 291 APPLICATION

I have tried to trim the length still couldn’t get this as length is not same for every subject lines.
I would be thankful to you if I get a solution on it.

Best Regards,
Preety

Can anyone please update on this?

1 Like

Then try setting the condition like this

arr_subjectlines.Any(Function(a) item.Subject.ToString.Trim.Contains(a.ToString.Trim))

If it’s true it goes to then block or to else block

It’s just the other way of comparing

Cheers @TIN_RPA

1 Like

Hi @PalaI have tried this arr_subjectlines.Any(Function(a) item.Subject.ToString.Trim(a.ToString.Trim)) however It didn’t work. I am getting below SS error-

Could you please check it?

Thank You!

Regards,
Preety

1 Like

After .Trim u missed .Contains

Mention like this

@TIN_RPA

1 Like

Yes, I missed that .contains. It is now working.

Thanks a ton !

Best Regards,
Preety

1 Like

Hi @Palaniyappan,

I would like to ask one more question on this, After comparison between the outlook mail subject and Input file how will we save that email with that name (which bot will get after comparison ) ?

and is Convert.ToBase64String mandatory for this?

I would appreciate your prompt reply here !

Regards,
TIN RPA

Hi @Palaniyappan,

Could you please reply on this?

Thanks in anticipation !

You can simply save with Save Mail Message Activity
https://docs.uipath.com/activities/other/latest/productivity/save-mail

@TIN_RPA

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