How to find out if Mail has attachments or if it has no attachments?

outlook
activities

#1

Hello Everyone, I’m a beginner in UI Path and I have been trying my hands on Email Automation. While Practising outlook automation I came across Save Attachment Activity. I was just curious if there is a way to determine if there is/are any attachment(s) in the mail. Or if there is a way to fire a message to sender if in case there is no attachment in the mail.

Thank you .


How to check existence of email attachment
How to read only emails which has the attachments
Mail attachments empty or missing
#2

Yes You can use “Item.Attachments.Any”

Regards…!!
Aksh


UiPath not able to save outlook attachments
#3

Can I get more details?
Thanks :slight_smile:


#4

Yes it will check System.Net.Mail.AttachmentCollection(Item is here a System.Net.Mail message) is having any attachment or not and with .Any() will return the output in boolean like true or false so i am using it directly inside if condition. You can use count as well to get the attachment collection counts and make your own conditions to proceed further.

Regards…!!
Aksh


#5

@aksh1yadav

When I use this condition it is always TRUE even when the mail has no attachments.


#6

Try Message.Attachments.Count as well and let me know.

Regards…!!
Aksh


#7

would you happen to know how to check if the email has excel attachments, so specific attachments?

In my process, someone could email with just an excel attachment, or three attachments, one of which is excel, or multiple attachments, none of which are excel etc.

If there is no excel attachment in the email (even if it has multiple different attachments, as per the examples above) I need to respond saying “invalid email” (ie I have to check each email for an excel attachment, I cant use the filter in the get outlook mail messages activity, as I need to respond to every email).

In my if condition I tried using:

item.Attachments.ToString.Contains(".xlsx")

I tested this on an email with an excel attachment, but it failed, showing a message box i put in place saying “no excel attachment” lol

Any help would be great!
thank you


#8

Will you be able to use this?

If (item.Attachments.Where(Function(x) x.Name.Contains(".xlsx")).Count >0)
{
//Valid Email
}
else
{
//Invalid Email
}


#9

Yes we can by using following attached snapshot way and for your reference here is the already discussed forum link:


Regards…!!
Aksh


#10

Hey @saivig,
try not having any image in your signature if you have. (if condition .Attachments.Any is always True)

Jakub


#11

I didnt find .Attachment property for this. why?


#12

Check the type of object you are firing. it is System.Net.Mail.MailMessage type or not.

Regards…!!
Aksh


#13

Solved!


#14

When i am using this property- Attachements.Any then the loop does not go in then condition.
Can you tell what could be possibly wrong?


#15

Did u mention item.Attachments.Any (or) Attachments.Any?

Thanks,
Sreekanth.k


#17

@SHAISTA Once check your mail for attachments mailattachmnts.xaml (9.1 KB)Once execute this file with your mail credentials
Thanks,
sreekanth.k


#18

Hi sreekanth

Although there are no attachements in few mails,then also your program is also not executing else loop.


#19

@shaista,For me It’s working fine.Check your code again.If there are no attachments why will it execute Then,It should execute Else