How to read latest email with specific subject

Hello UiPath forum Family,
I am trying to read all emails with specific subject name for example (Subject = "Excel Report ") extraction of all mail with same subject is successful but I just need read only latest mail and download attachment
If two subject name mail is in latest one mail the bot will read first which came recently

Hi @sandip.shahane

Check with the Count of the Subject and Proceed with save attachment!

Regards

Hello @pravin_calvin I was try some still it’s not working

Hi @sandip.shahane

You steps would be a Follows below!

Get mail message Activity!

For each Item in Mailout

If Item.Subject.equals(“YourSubjectKey”)

Then Save attachments!

Regards

1 Like

Hello @pravin_calvin

Get mail message Activity!

For each Item in Mailout

If Item.Subject.contains(“YourSubjectKey”)

Then Save attachments!

“Equals” is not work I used "Contains"this logic will fetch mails but bot save more than 2 files because there is more than one mail of same subject. I need just latest one mail

Hi @sandip.shahane,

In your get email activity you can set the property Top to 1 and you will only fetch one email.

I don’t know if you use Outlook but this is the example for that:

Also for the solution suggested before, you could use a Break activity after saving the attachment of the first email inside your For Each loop.

Best,
Daniela

3 Likes

Hi @sandip.shahane

In addition to @Daniela_Colina’s latest post, I would look updating your Exchange Package so you can add a filter expression to find the exact email and the most recent.

image

So,

  1. Select “Newest First” in “OrderByDate”
  2. Insert “1” into “Top”
  3. Insert expression into the “FilterExpression” field. Insert this expression: "subject:Excel Report "

The UiPath documentation for Get Exchange Mail Messages and the filter examples are really good. You can add many filter types.

Hopefully this helps :slight_smile:

1 Like

Hi @Steven_McKeering ,
I am using Gmail get mail message activity
I was try date order : “News first” and filter expression :arrow_right: “subject:Excel Report” but it showing this error
image

Hi @Daniela_Colina ,
I am using Gmail get IMAP mail message
I was try you solution but couldn’t work can you please tell me how filter condition in get IMAP mail message activity.
Here is image

Hi

Your expression looks fine
Hmm

May be You can try this approach:

  1. Read the mails using Get IMAP mail activity and store in mails variable.
  2. Now use the below linq query using assign activity

mails= mails.Where(Function(mail) mail.Subject.ToString.ToUpper.Contains(“EXCEL REPORT”)).ToList()

the after the assign activity, mails variable will only contain the mail which had subject containing the word you want in it.

Cheers @sandip.shahane

1 Like

Hello @Palaniyappan ,
Thank you for sweet words I have one doubt this expression will get latest first mail only and then next mail with same subject will not save because i want this logic if subject name mail is there continue one by one bot will pick only first new mail

Regards,
Sandip

Hi @Daniela_Colina ,
I used break activity in for each loop so bot iterating email one by one but save only latest file attachment

Thanks for help

Regards,
Sandip Shahane

1 Like

Hi @sandip.shahane,

Have you tried with the filter “SUBJECT ““Excel Report””” ?

There are examples on how to filter using the IMAP activity in uipath’s documentation:

Best,
Daniela

Hi @Daniela_Colina ,
Yes I am exploring those expressions also

1 Like

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