Kontakt os

Send SharePoint list item attachments by mail using Power Automate

Learn how to send SharePoint list item attachments by e-mail, using Power Automate and JSON


Step 1
Create a new automated cloud flow and select the trigger action for a selected item

Insert Email as input

Power Automate automated cloud flow with the For a selected item trigger and an Email text input parameter added

Step 2
Initialize a variable as an array and name it attachments

Power Automate Initialize variable action configured as an Array type named attachments

Step 3
We want to know which attachments we have available in the list item.

Insert an get attachments action.

The Id should be from our trigger action

Power Automate Get attachments action with the list item Id from the trigger inserted as the identifier to fetch all attachments for the selected item

Step 4
We want to append the content of each attachment to our array

To do this, insert an apply to each action, and insert the body from get attachments

Power Automate Apply to each action with the body output from Get attachments as its input to loop over each attachment

Step 5
Insert an get file content action inside the apply to each, and use the Id from get attachments, in the file identifier

Power Automate Get file content action inside Apply to each using the Id from Get attachments as the file identifier to retrieve each attachment’s binary content

Step 6

Insert an append to array action and insert below code.

{
  "Name": @{items('Apply_to_each')?['DisplayName']},
  "ContentBytes": @{body('Get_file_content')}
}

Power Automate Append to array variable action adding a JSON object with Name from DisplayName and ContentBytes from Get file content to the attachments array

Step 7
Outside the apply to each action insert an send an email action.

Click the switch to array icon, and insert the variable attachments

To should be the email input from the trigger action

Power Automate Send an email action outside the loop with the attachments array variable in the Attachments field and the trigger Email input in the To field

The flow is ready
This is how the entire flow looks like

Complete Power Automate flow showing all steps from the For a selected item trigger through initialize variable, get attachments, apply to each loop, and send email actions

Start flow from a button
We can start a flow from a button on the list.

SharePoint list showing a custom Send mail button column formatted with a mail icon that triggers the flow when clicked

Create a new text column and insert the following JSON code in format this column

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "align-items": "center",
    "margin-top": "2px",
    "margin-bottom": "2px"
  },
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\":\"<Insert-Flow-Identifier-Here>\", \"headerText\":\"Send mail with attachments\",\"runFlowButtonText\":\"Send mail\"}"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "class": "ms-bgColor-themePrimary ms-fontWeight-bold ms-bgColor-themeDarker--hover"
      },
      "style": {
        "height": "30px",
        "width": "2x",
        "text-decoration": "none",
        "display": "flex",
        "align-items": "center",
        "text-align": "center",
        "justify-content": "center",
        "margin": "5px",
        "color": "#fff",
        "border-radius": "3px",
        "cursor": "pointer"
      },
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "iconName": "Mail",
            "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover ms-font-m",
            "title": "Details"
          },
          "style": {
            "color": "#fff",
            "flex": "none",
            "margin-right": "8px",
            "margin-left": "10px"
          }
        },
        {
          "elmType": "span",
          "style": {
            "margin-right": "10px"
          },
          "txtContent": "Send mail"
        }
      ]
    }
  ]
}

Replace <Insert-Flow-Identifier-Here> with your flow identifier.

You get the flow identifier from the export menu

Power Automate flow detail page with the Export menu open in the top ribbon used to access the flow identifier

Copy the entire identifier

Export dialog showing the complete flow identifier string to copy and paste into the column JSON actionParams

Finally we can run our flow, and receieve an e-mail with the list attachments

Email received with the SharePoint list item attachments included as file attachments sent via the Power Automate flow

Pinksky bruger cookies for at forbedre funktionaliteten på denne hjemmeside. Du bestemmer selv hvad vi må bruge. Læs mere i vores cookiepolitik.