Iterating through email attachments

How do you go on to iterate through attachments of a mail and download only those that contain a certain text in the name?

Thank you for the help!

LE: I already have a way to iterate thourgh the attachments and check for the naming but I don t know how to save the attachment to folder. (activities need MailMessage object, I need to save Mail.Attachment object)

Hi @Androk

Check with the reference link below!

Regards

Hi, thanks for the general direction but maybe I wasn’t clear enough. Let’s say I have an email with 10 attachments, pdfs, 5 of them contain a certain word in their naming, 5 don’t. I need to download only the 5 that contain that word, from one email.

HI @Androk

Have a look on the thread to download the attachment based on the value

Download email attachment with UiPath - RPA Geek.

Regards
Gokul

1 Like

Thanks but I need to check if the name of the attachments contains a certain text not the email subject.

Hi @Androk

Have a look on the thread

To get the filename of the attachment and process you condition

Regards
Gokul

okay so where will be the source of name of the attachments?

you have saved somewhere else or it will be from excel?

Not saving the names anywhere, checking while iterating through the attachments, I ve already followed what you suggested, the problem is the activity Save Attachments does not take the type of argument Mail.Attachment it takes Mail.Message. Any solution for that?

That is what iam asking for with what you will be checking any example of the attachment name do you have?

I’m checking if the attachment name (they are all pdfs) contains a certain word like “packing”, some contain it some don’t… i just want to download those that do. An email can have 20 such attachments.

This packing will be anywhere in the attachment name like at start end or middle?

Hi @Androk

Use the below expression in if condition!

item.Attachments.Tostring.Contains(“packing”)

Then use save attachment to save the attachment with only name packing

Regards

@Androk

Here is the work around try it in your side

  • For each mail message
    • For each Attachments in item.attachments
      • Assign “attachmentname” (String) =“packing”
      • If Attachment.Name.Contains(“packing”)
        - Save Attachments pass item as mailMessage and pass your desinaation and in properties use the assigned variable “attachmentname” in filter option

Here is the workflow for your ref

Sequence.xaml (13.1 KB)

Regards
Gokul

1 Like

It’s at the start usually, could use StartsWith to, but Contains should work aswell.

I’ve already tried this, and it does not return any message even though some match that, from what I understand item.Attachments.Tostring.Contains(“packing”) works only for extensions.

Okay try that steps which i provided in your side and let me know
it worked perfectly for me

Regards
Gokul

1 Like

Thanks for all the help and the example.

I managed to resolve it like this:

Seems more elegant to me and works perfectly! Thanks a lot!

1 Like

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