Azure Logic App: send an email with multiple attachments

Diego Polidori 26 Reputation points
2021-12-03T08:23:29.933+00:00

Hello
I am new to Logic Apps and I have to solve the following problem
I have to send an email when one or more files are uploaded from a web UI to Azure ffile share storage.
I was thinking to use a HTTP trigger and pass in a POST request all the parameters that are dynamic, that is can change based on the user account: the recipient of the message, the Cc list, and the list of files uploaded which are to be attached to the mail
So, JSON object to send in the HTTP should be like
{
"to": "xxx@永爱不变 .zzz",
"subject": "Bla bla",
"html":"Mail body",
"attachments":["file1.csv","file2.txt"],
"path":"path-to-azure-storage"
}
I tried to use a foreach connector to build the full path of the file to attach, but never worked: I received either a 'compilation error' or an email without attachments
Thank you for your help

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
0 comments No comments
{count} votes

Answer accepted by question author
  1. MayankBargali-MSFT 70,986 Reputation points Moderator
    2021-12-03T11:19:40.82+00:00

    @Diego Polidori If you need to attach multiple files then you need to create an array of attachments and then pass the attachment variable to your Send email action.
    In my workflow, I am getting the list of files in a particular blob, and after getting the blob content I am appending the content and fileName to the array variable in for loop of my workflow.

    As the send email action uses the attachment parameter as the array in the below format

    [{  
      "ContentBytes": "contentbytes1",  
      "Name": "fileName1"  
    },  
    {  
      "ContentBytes": "contentbytes2",  
      "Name": "fileName2"  
    }]  
    

    154770-image.png

    Note: I am getting the byte blob contents using $content as below

    {  
      "ContentBytes": "@{body('Get_blob_content_(V2)_2')?['$content']}",  
      "Name": "@{items('For_each')?['Name']}"  
    }  
    

    In my Send Email action, I am passing the attachments variable to the Attachment of Send Email Action.

    154720-image.png

    You can modify the flow and change the value as per your HTTP request body. Let me know if you need any assistance.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.