Checking MyMail for attachments that meet certain criteria

Hi all, I’m hoping you may be able to help.

Does anyone know how to check the condition of an attachment within an email, specifically when there may be multiple attachments saved in the same email?

For example, I have an email with 3 attachments - “Test1 PDF”, “Test2 Excel” and “Test3 Excel”. I would like to do something with that email if it contains an attachment where the file name contains the phrase “Test2”.

My issue at the moment is that I’ve been able to assign an attachment name, and use an If to see if it contains a certain phrase, but this only seems to work for the First/default attachment or Last/default.

Would anyone be able to advise? Thanks in advance!

Hi @sam.willson , you can use the below query to check if there is an attachment present with your desired name:

MailMsgVariable.Attachments.ANY(function(x) x.Name.contains("Test2"))

This will return a boolean value

Regards,

@sam.willson

What activity are you using for getting emails? We can use filters on that directly to return only the emaila which contain required attachment name…

For outlook mail message we cna do like this

"@SQL = ""urn:schemas:httpmail:attachmentfilename"" LIKE '%Test2.xlsx'"

Cheers

1 Like

Hi

You can use an expression like -

attachment.Name.Contains(“Test2”)

If the condition is true, you can perform the desired action on that attachment, such as saving it to a local folder or processing it further in your automation.

Thanks!!

Hi @vishal.kp thank you for this - this works perfectly! Thanks again for your help here!

1 Like

Hi @Anil_G thanks for your suggestion! At the moment I need it to retrieve all emails with an attachment - and then do the sorting from there (this is due to some other triggers we have in place which will forward emails to certain people in certain words are/aren’t included). Thank you for your suggestion, I will remember this for when I need to filter out certain emails from the start :grinning: thanks!

1 Like

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