How to send SharePoint file as email attachment using logic app azure ?

Priti Bogawat 0 Reputation points
2024-04-10T06:28:44.0166667+00:00

I want to send the SharePoint file as an attachment in the email through the logic app, so please help me with the in detailed steps to do it. How to connect Azure Logic App to Sharepoint, which folders to be picked, how to create a list or folders, and which action to be taken in the logic app.

I've taken the action as a "When an item is created or modified" in that it is asking me for the Site Address & the List Name, but I'm not getting what should I write in those above two fields. And how to create the lists in the SharePoint. So please help me with this.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,855 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,677 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 17,636 Reputation points
    2024-04-10T16:47:01.58+00:00

    @Priti Bogawat Thanks for reaching out. Here are some of the references for you on getting started with integrating SharePoint and logic apps.

    Here are high level steps on your requirement.

    • First, you need to create a connection between Azure Logic App and SharePoint. To do this, go to the Azure portal and navigate to the Logic App that you want to use. Click on the "Logic App Designer" tab and then click on the "New step" button. Select "Add a connection" and then select "SharePoint". Follow the prompts to sign in to your SharePoint account and create the connection.
    • Once you have created the connection, you can add a trigger to your Logic App. Select the "When an item is created or modified" trigger and then enter the Site Address and List Name for the SharePoint site and list that you want to monitor. If you don't know the Site Address and List Name, you can find them by navigating to the SharePoint site and list in your web browser and copying the URL. The workflow is triggered when a new item is created in a SharePoint list.
    • Retrieves the attachments of the new item using the "Get_attachments" action.
    • Loops through each attachment using the "For_each" action.
    • For each attachment, the workflow retrieves its content using the "Get_attachment_content" action.
    • Send an email using the "Send_an_email_(V2)" action, with the attachment added to the email as an attachment and the email body and subject specified in the action.
    • Finally, save and run your Logic App to test it.

    Screenshot of Logic app:

    User's image

    Sample code reference:

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "For_each": {
                    "actions": {
                        "Get_attachment_content": {
                            "inputs": {
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                                    }
                                },
                                "method": "get",
                                "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://microsoftapc.sharepoint.com/teams/SampleSharepoint'))}/tables/@{encodeURIComponent(encodeURIComponent('xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'))}/items/@{encodeURIComponent(encodeURIComponent(items('For_each')?['Id']))}/attachments/@{encodeURIComponent(items('For_each')?['Id'])}/$value"
                            },
                            "type": "ApiConnection"
                        },
                        "Send_an_email_(V2)_copy": {
                            "inputs": {
                                "body": {
                                    "Attachments": [
                                        {
                                            "ContentBytes": "@{base64(body('Get_attachment_content'))}",
                                            "Name": "@{items('For_each')?['DisplayName']}"
                                        }
                                    ],
                                    "Body": "<p>tette</p>",
                                    "Subject": "SharePoint : New Item has been added",
                                    "To": "xxxxxxx@microsoft.com"
                                },
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['outlook']['connectionId']"
                                    }
                                },
                                "method": "post",
                                "path": "/v2/Mail"
                            },
                            "runAfter": {
                                "Get_attachment_content": [
                                    "Succeeded"
                                ]
                            },
                            "type": "ApiConnection"
                        }
                    },
                    "foreach": "@body('Get_attachments')",
                    "runAfter": {
                        "Get_attachments": [
                            "Succeeded"
                        ]
                    },
                    "type": "Foreach"
                },
                "Get_attachments": {
                    "inputs": {
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                            }
                        },
                        "method": "get",
                        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://microsoftapc.sharepoint.com/teams/SampleSharepoint'))}/tables/@{encodeURIComponent(encodeURIComponent('xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'))}/items/@{encodeURIComponent(encodeURIComponent(triggerBody()?['ID']))}/attachments"
                    },
                    "runAfter": {},
                    "type": "ApiConnection"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "When_an_item_is_created": {
                    "evaluatedRecurrence": {
                        "frequency": "Second",
                        "interval": 3
                    },
                    "inputs": {
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                            }
                        },
                        "method": "get",
                        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://microsoftapc.sharepoint.com/teams/SampleSharepoint/'))}/tables/@{encodeURIComponent(encodeURIComponent('xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'))}/onnewitems"
                    },
                    "recurrence": {
                        "frequency": "Second",
                        "interval": 3
                    },
                    "splitOn": "@triggerBody()?['value']",
                    "type": "ApiConnection"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {
                    "outlook": {
                        "connectionId": "/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg/providers/Microsoft.Web/connections/outlook",
                        "connectionName": "outlook",
                        "id": "/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Web/locations/southindia/managedApis/outlook"
                    },
                    "sharepointonline": {
                        "connectionId": "/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg/providers/Microsoft.Web/connections/sharepointonline",
                        "connectionName": "sharepointonline",
                        "id": "/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Web/locations/southindia/managedApis/sharepointonline"
                    }
                }
            }
        }
    }
    
    
    0 comments No comments