Saving Mulitple Attachments to different Folders from One Outlook mail

Hi all

I need to see if a mail message contains more than one attachment and if it does save them to separate folders - the names of those folders being the names of the attachments.

I can use Get Emails as Outlook is installed on the Dev environment

I then thought I could use Save Attachments to do the trick but this seems to only allow to save all attachments for that given mail message.

Please can I ask if anybody knows how to write code to save one attachment at a time and then loop through to save the next attachment (if there is more than one?)




You are on the write path. Use the Get Outlook Mail Activity and then a for each activity that will go through all messages, inside this for each, you need an if activity, that will check the number of attachents in an email using the, your condition could be something like Mail.Attachments.Count() <= 1 . What this is saying basically is if the mail message has attachments that are equal to or less than one do something and then in your else part.

Create another for each activity now this will go through each attachment in a mail and save it. I figured this might be a bit difficult to understand as it is hard for me to explain, so i created a starting template for you, hope it helps solve your problem, and please let me know if you need further assistance with this.

here is a sample: Main.xaml (7.4 KB)

Hey @SenzoD, this looks amazing - thank you so much for taking the time to do this. Makes perfect sense when I look at it too. My overall task is to get the date of the email which I can believe I can do using message.headers(“Date”) and the name of each attachment. I’ve then got to create a folder using the name of each attachment (and date of the email) to save that attachment to.

Would I be able to use the same set up you’ve done to create the folders first (by using the create path function I think it is) and then using your save attachment functions to save each attachment in the newly created folders? So if it creates 3 folders in the order of X, Y, Z it will save the 3 attachments in the same X, Y, Z order so the right attachment folder?

Regardless of weather you can answer or not, thank you so much for the help, I really do appreciate it.

@jordrowley, anytime man, glad I could help

Yes that is possible, and the steps you mentioned are all correct, you will need to tweak a couple of things and your logic will get a bit complicated. If you get stuck somewhere, let me know.

Hey @SenzoD sorry to keep messaging you, i’m struggling to get the name of the attachments - I figured that in the location to save the attachment, I could create a folder using a given path and the name of the attachment - I’ve been trying all sorts of things to get the name of the attachment but keep coming up again ‘conversion errors’ - I’ve tried various types of variables and then properties to try and give me the name, but without luck. Please can I ask if you know how to do this?

Thanks so much

@jordrowley, no worries dude

Check out the below, so in your case you will use the function inside the for each, that is for the emails that has multiple attachments:

I believe the logic from these two, should be sufficient to get you moving to the next step, but if its still unclear let me know

@SenzoD Sure, I will have a go now, thank you :slight_smile:

1 Like

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