Hello all! It’s been at least two years since I have posted something technical on my Salty Blog, pathetic right?. This how-to in my opinion was too good not to share as I believe that it will help others that are facing/have faced this issue.
The ability to email attachments from a list is one of those pain points that I seem to face all of the time. This documentation will take you through the process of setting up a new Flow that will grab all attachments for a single list item and will then email those attachments back out to the intended target.
Before I begin, let me preface this post stating that I did not come up with this. I found a couple of posts and podcasts but I wanted to compile this working version into one blog post.
I was searching for an answer on this issue late last year and attending one of Laura Roger’s weekly Power Hours and she presented on this. Here is a link to that original broadcast: SharePoint Power Hour: Flow Attachments & Files . If you follow the recording to the end, you will notice that Flow was not behaving properly. Well, I could not get it to work either and after a month of trying different things, I gave up.
A couple of months later I, I received an update from Microsoft’s Blog on Flow which is named Flow of the Week. This particular flow caught my eye: Send multiple attachments on a single email. I couldn’t believe it! This was exactly what the doctor ordered or at least I thought it was. I had setup the Flow as explained in the blog post but when I would run the Flow, I would receive the following message: “No input parameters provided. Please provide required input parameters ‘To’, ‘Subject’ and ‘Body'”
You’ve got to be kidding me!!!!!! Why is this not working for me?!?!?!?! I just want to send an email with the list attachments!!!!! I need this to work!!!!!
Ok, calm down……… After a couple of weeks had passed and after I tried all that I could think of to get around this error, I went back to that Microsoft blog post and noticed a comment by Vytenis Jazbutis. He explains how he was able to get around this with a “fix” for the issue of the final “send email” step. It doesn’t like and doesn’t want to add the full “file content” file from the array as an email attachment. What it wants instead is the .$content property within the file contained in the array.
I have decided to recreate the blog post showing the new way of grabbing the attachments with Vytenis’s fix. Once again, all props goes to Laura, Sunay and Vytenis of this.
With that being said, let’s dive into this and build out this Flow!
- Add a new “SharePoint – Create item” trigger and select the correct SharePoint Site and List.
*** Please ensure that you already have SP List created that allows storing multiple attachments on the items in it.
- Add a new “Schedule – Delay” step
*** I added this additional “Delay Step” because I was getting inconsistent results. Sometimes the trigger would fire too early and would send a blank email without grabbing the attachments. By adding this 30 second delay, it will give Flow the ability to run each step in the process before sending the email. You may not need this in your environment but in my experience even with SharePoint Designer workflows, I have to add these more often than not.
- Add a new “SharePoint – Get attachments” step
*** This step will be grab all of the attachments added to the newly created list item. Use the Site name and List name from the previous step. We want to then pipe the output “ID” from the trigger, to the input ‘ID’ field. - Add a new “Variables – Initialize variable” step
*** This variable will be used to store all of the attachments in a single array.
- Add an “Apply to each” step.
- Click inside of the *Select an output box and click the “Body” output from the “Get attachments” section
- Click the “Add an action” button and select “SharePoint – Get attachment content”
- For the ID field, select the “ID” output from the “When an item is created” trigger section
- For the File Identifier field, select the “Id” output from the “Get attachments” section
- Click the “Add an action” and select “Variables – Append to array variable”
- For the Name field, select “attachmentArray” from the dropdown. (this was created in step 4)
- For the Value field, type in the following JSON statement:
-
{ "ContentBytes":, "Name": }
- For “ContentBytes”, click between the : and , and then click on the “Expression” output
- Type in the following expression: body(‘Get_attachment_content’).$content and click the ‘OK’ button
*** “Get_attachment_content” is the name of the step created in 5b. Don’t forget the underscores for spaces.
-
- For “Name”, click between the ” and : and select the “DisplayName” output from the “Get attachments” section
*** See “Note” below on additional details about the “ContentBytes” parameter
The completed step should look like the one seen here
- Add a new “Office 365 Outlook – Send an email” step
*** Note: Use whatever mail client that you have setup to run this step.- Fill in all of the required fields (if applicable to your mail client).
*** I have a list value that I am using to populate my “To” field. - Click the “T” icon next to the Attachments Name field. This switch will change the attachments control from “Detail inputs for array item” to “Input the entire array”
- For the Attachments field, select “attachmentArray” from the “Variables” section.
- Fill in all of the required fields (if applicable to your mail client).
- The completed Flow should look like the following:
Save your Flow, then go to your list and create a new list item with attachment(s) to test. Remember to be patient if you put in the delay step. You should receive an email with the attachment(s) that you added to the list item.
This solves a lot of issues that I was having and I hope that it will help you in some way.
Stay Salty!
This post is pure gold! I have tested it and it works smoothly.
Many thanks for your work!
Hello, Thanks for this post. For me, Its sending out two emails. One with just one of the attachment and other with both attachments.
That’s odd. Have you double checked to see if you are point to the correct fields?
Works great! I had been fighting with the attachments for some time but the update to the array variable code was what I needed! Ral…if you’re getting two emails it’s because you need to take the “Send an email” step out of the “Apply to Each” section and make it the last step.
It’s working perfectly..very nice article..
This is a really great article. I came here via a link from a MSFT forum. Did you find a solution for when the attachments are text files with a .txt extension?
fantastic!!
Not yet but it’s something that is needed.
I think I found a solution
https://social.technet.microsoft.com/wiki/contents/articles/51752.send-list-item-attachments-to-internalexternal-users-through-email-sharepoint-online-microsoft-flow.aspx
You have to enclose the body function with a base64 function to encode the txt file ( I added an if statement to see if the attachment ended with .txt to determine if I had to add the encoding or not)
Hi, I’m also facing an issue with several emails being sent. Each one appends a new attachment, so for example if 3 attachments are added then I’ll get 3 emails, one with 1 attachment, 1 with 2 attachments and 1 with 3 attachments. I followed the steps here but it keeps happening 🙁 any advice at all?
Excellent! Thanks for sharing this, I’ll update the post after I test on my end.
Graham, where did you place the send email step? Make sure that it is outside of the apply to each step and place it at the very end of the Flow.
I have a similar problem. I am trying to trigger an email if the list item has or does not have an attachment and the flow will send two emails. Once with the attachment and one with out. Any thoughts on how I can get this to trigger one or the other?
Hey Eric, thanks so much for your guidance. A rogue function inside the email body itself was causing this to happen: join(split(items(‘Apply_to_each’)?[‘AbsoluteURi’],’ ‘),’%20’)} which was inside a link. I think I was actually trying to link to attachments on the SP server, but have taken it out now and it is working as I can finally take the email out of for-each. Always the simplest thing! Cheers 🙂
This post is f’ing brilliant! This process even works when pulling attachments from another SharePoint list. Thank you so much!
Thank you! This works perfectly for list items with attachments. What if there are items without attachments that I want email notifications for as well? This process isn’t picking them up if there is no attachment. Creating another flow results in two email notifications for items that do have attachments. Do you know a quick fix?
Dennis, I tested my Flow this morning and was able to send an email without an attachment with no issue. Do you have an added step in the process? Also, is there an error that is thrown when the Flow runs?
Melissa, have you added any other steps to the process? Where did you place the email step? Make sure that it’s outside of the ‘Loop through Announcements List’ step
Hi, Yes I have a condition before the delay step. Which meant I had to push the initialize variable based column to above the condition otherwise it would not allow me to initialize variable. I’m picking this is the issue but flow won’t allow the initialize variable to be below the condition.
Great article!
Thank You!