How to save a specific attachment in outlook

Hi,

I’m trying to save an Excel file in the attachments of an email. There is only one attachment to the email. but for some unknown reason Ui path thinks the logo in the text is also an attachment and saves it with the Excel file.
i triied to loop through the attachments and extract the xlsx file but I can’t figure out the method for the type

Edit: I found the solution.
SOLUTION: apply this filter: “.*(?i)(.xlsx|.xls)”

hope this would help you

Cheers @B.D

1 Like

hmm I tried to apply the filter method: “.(?i)(.xlsx|.xls)” posted by Mikkel_Nelson and ".(.xlsx|.XLSX|.xls|.xls)" by Santan_Barnwal. both don’t seem to work. no file ist saved. any idea ?

Hey,

I work for me. Please find the screenshot below from my process. I get the wav file from the attachment and save in a folder.

You can use it with OR condition in IF activity

Path.GetExtension(attachment.Name) = “.xls” OR Path.GetExtension(attachment.Name) = “.xlsx”

Thanks,
Ashok

Hi @B.D,

Please use ‘Filter’ option in ‘Save Attachment’ activity. And please use “.pdf” in the ‘Filter’ box. It will only save the .pdf files. Hope it will work.

Thanks & regards,
Apurba

1 Like

hi, I tried a diffent approach by using the filters. The workflow from the other thread you are using seems to be a bit too long and unnecessaryfor such small task. If I can get the filters to work the processing time will be much shorter.

hope this would help you
select.zip (9.7 KB)

because we wont able to get the attachments file extension inthe filter property of get outlook itself, and only we can check whether attachment is there or not like this
"@SQL=urn:schemas:httpmail:hasattachment = True"

so we can use this condition in the filter property so that it will filter only the mailmessage with attachments

and to check with the file extension we need to get the list of mail message and then we need to iterate through each mail with its attachment and it wont impact a lot with workflow performance as we wont have that much attachment with each mail

Cheers @B.D

i’m searching for a solution where it filters the xlsx file from the other attachments abd saves it. For this I wanted to use the filter option in the properies first, but a loop through the attachments and seperation of the xlsx file would also do the job.

Yah in filter option we can check whether a attachment is there are not but not with what kind of attachement
That’s why we need to go for looping
Cheers @B.D

Hi, according to what I read and from the videos, you don’t need to loop. there are many filter types which make certain operations such as filtering through looping obsolete with 1 line of code. But I can’t get it to work. the workflow you attached searches for xlsx files but doesn’t seperate them from the other attachments. it is only a searching. but thanks anyways.

well once after searching if the attachment name has .xlsx, it goes to THEN part and obviously it will take only that file right, as it is in the current iteration

Cheers @B.D

Well that’s the problem. I was already there. The system.net.mail.mailmessage type doesn’t allow any seperation of the attached elements, even if you loop through the attachments. save attachment which is a method of system.net.mail.mailmessage doesn’t work with it. you have to use streams and system.net.mail.attachment type to get around this. the solution with stream posted in the thread, shared by you is right. but I didn’t want to use it first because I don’t quite understand this method and because the filter method would have done the job with 1 line if it did work…

nevertheless thanks again

Create a list of file paths and pass in AttachmentsCollection Property. Make sure no path is invalid, otherwise activity will fail.

I don’t understand. for what do I need the sendoutlookmail activity if I’m trying to search, seperate amd store the files. and what is the collection good for ?

Hi Palaniyappen,

to update you on my problem… the filter: “.*(?i)(.xlsx|.xls)” works! I had to change a time condition, after changing it, the filter works fine

1 Like

Cheers @B.D