Flow · Office 365 · SharePoint

Emailing List Attachments in Office 365

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!

  1. 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.
  2. 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.
  3. 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.
  4. Add a new “Variables – Initialize variable” step
    *** This variable will be used to store all of the attachments in a single array.
  5. Add an “Apply to each” step.
    1. Click inside of the *Select an output box and click the “Body” output from the “Get attachments” section
    2. Click the “Add an action” button and select “SharePoint – Get attachment content”
    3. For the ID field, select the “ID” output from the “When an item is created” trigger section
    4. For the File Identifier field, select the “Id” output from the “Get attachments” section
    5. Click the “Add an action” and select “Variables – Append to array variable”
      1. For the Name field, select “attachmentArray” from the dropdown. (this was created in step 4)
      2. For the Value field, type in the following JSON statement:
        1. {
        2. For “ContentBytes”, click between the : and , and then click on the “Expression” output
        3. 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.
      3. 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
  6. Add a new “Office 365 Outlook – Send an email” step
    *** Note: Use whatever mail client that you have setup to run this step.

    1. 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.
    2. 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”
    3. For the Attachments field, select “attachmentArray” from the “Variables” section.

  7. 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!

20 thoughts on “Emailing List Attachments in Office 365

  1. This post is pure gold! I have tested it and it works smoothly.
    Many thanks for your work!

  2. Hello, Thanks for this post. For me, Its sending out two emails. One with just one of the attachment and other with both attachments.

  3. 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.

  4. 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?

  5. 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?

  6. 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?

  7. 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 🙂

  8. This post is f’ing brilliant! This process even works when pulling attachments from another SharePoint list. Thank you so much!

  9. 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?

  10. 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?

  11. 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

  12. 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.