Home > database >  Getting the files from Azure Blob and sending them in one email
Getting the files from Azure Blob and sending them in one email

Time:09-06

I have a setup that is exporting all the json files generated from an API sent to an email address upon a request sent to a shared mailbox, but the thing is that currently logic app is sending out separate emails, one json per email, so it's 7 emails in my case.

My final solution would be sending all the json files in one email. Have tried to figure out the connector methods, but seems that I cannot find that out. Tried to Google of course, but no luck.
Would really appreciate any help!

Current setup looks like this:

Azure Logic App 1:
azure logic app 1

Azure Logic App 2:
azure logic app 2

CodePudding user response:

You need to build an array of all of the attachments outside of the loop.

This is the flow I tested with ...

Flow

... the two important points are:

Construct an Attachments Array

As you can see, I've declared a variable at the top Attachments of type Array.

Get your blobs and then loop over each one of them.

Within the loop, get the contents of the blob and then add an object to the array that looks like the following JSON structure ...

For Each

This is the Peek Code of the array item, noting that I am encoding the content as base64 ...

{
    "inputs": {
        "name": "Attachments",
        "value": {
            "ContentBytes": "@{base64(body('Get_blob_content_(V2)'))}",
            "Name": "@{items('For_Each_Blob')?['DisplayName']}"
        }
    }
}

Send the Email

Now, when you send the email, refer to the array as the contents of the Attachments parameter.

Send Email

That should get the job done for you, it worked for me.

CodePudding user response:

Have you tried adding the output of the GetBlob Content to an array or adding it into a string? https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-create-variables-store-values#initialize-variable and then using this variable to create the email body?

  • Related