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.
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.
Thanks
Jordan
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?