Azure Logic App: send an email with multiple attachments without Blob

Barak Stein 1 Reputation point
2022-11-14T08:37:49.98+00:00

Hi,

I currently have a Logic app which receive a HTTP request that contains list of To, subject, mail body and an optional attachment file.
It works perfect but I would like it to be able receiving multiple files data and attach those files - no matter how much were received.
Currently, it checks if there is a parameter named "AttachmentName" in the request body if so it takes this as the file name and also collect the "AttachmentContent" parameter as the file data as a string format.
I can change if required the data sent to the logic app in order to work as expected.

I've tried looking for it on the web and it seems like it should be easy but everything I tried just does not work.
In addition, I found a lot of solutions which uses Blob but I don't - only from HTTP request

This is my current logic app:

"definition": {  
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",  
        "actions": {  
            "Condition": {  
                "actions": {  
                    "Send_an_email_(V2)": {  
                        "inputs": {  
                            "body": {  
                                "Attachments": [  
                                    {  
                                        "ContentBytes": "@{base64(triggerBody()?['AttachmentContent'])}",  
                                        "Name": "@{triggerBody()?['AttachmentName']}"  
                                    }  
                                ],  
                                "Body": "<p>@{triggerBody()?['Body']}</p>",  
                                "Subject": "@{triggerBody()?['Subject']}",  
                                "To": "@{join(triggerBody()?['To'], ';')}"  
                            },  
                            "host": {  
                                "connection": {  
                                    "name": "@parameters('$connections')['office365']['connectionId']"  
                                }  
                            },  
                            "method": "post",  
                            "path": "/v2/Mail"  
                        },  
                        "runAfter": {},  
                        "type": "ApiConnection"  
                    }  
                },  
                "else": {  
                    "actions": {  
                        "Send_an_email_(V2)_2": {  
                            "inputs": {  
                                "body": {  
                                    "Body": "<p>@{triggerBody()?['Body']}</p>",  
                                    "Subject": "@{triggerBody()?['Subject']}",  
                                    "To": "@{join(triggerBody()?['To'], ';')}"  
                                },  
                                "host": {  
                                    "connection": {  
                                        "name": "@parameters('$connections')['office365']['connectionId']"  
                                    }  
                                },  
                                "method": "post",  
                                "path": "/v2/Mail"  
                            },  
                            "runAfter": {},  
                            "type": "ApiConnection"  
                        }  
                    }  
                },  
                "expression": {  
                    "and": [  
                        {  
                            "contains": [  
                                "@triggerBody()",  
                                "AttachmentName"  
                            ]  
                        }  
                    ]  
                },  
                "runAfter": {},  
                "type": "If"  
            }  
        },  
        "contentVersion": "1.0.0.0",  
        "outputs": {},  
        "parameters": {  
            "$connections": {  
                "defaultValue": {},  
                "type": "Object"  
            }  
        },  
        "triggers": {  
            "manual": {  
                "inputs": {  
                    "schema": {}  
                },  
                "kind": "Http",  
                "type": "Request"  
            }  
        }  
    }  

Thanks in advance

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

2 answers

Sort by: Most helpful
  1. MayankBargali-MSFT 70,986 Reputation points Moderator
    2022-11-16T09:59:49.623+00:00

    @Barak Stein Thanks for reaching out. Can you please confirm if you want to attach the blob file as the attachment on your send email action, but the blob path needs to be dynamic and passed through your http trigger. If my understanding is correct, then you can leverage the below workflow. Attaching the Code View for your reference.

    Request Body: Array of file paths

    {"path" : ["/test/CodeView.txt", "/test/img.png"]}  
    

    In case if you want to send multiple attachments as dynamic you need to define the array and append the content and file name of your attachments as below.

    [  
      {  
        "ContentBytes": "base64byte",  
        "Name": "attachmentName1"  
      },  
      {  
        "ContentBytes": "base64byte",  
        "Name": "attachmentName2"  
      }  
    ]  
    

    Workflow :
    260905-image.png

    Let me know if I understood your requirement and share example so I can assist you.

    1 person found this answer helpful.

  2. Jaffar Syed 0 Reputation points
    2023-11-07T16:18:46.68+00:00

    @MayankBargali-MSFT

    I missed to initialize var but now i am getting this error for loop - "The execution of template action 'For_each' failed: the result of the evaluation of 'foreach' expression '@triggerBody()?['path']' is of type 'Null'. The result must be a valid array." . I really need some help -

    looking at this post i just cant seem to find where is the 'path' values set ?

    I want to attached all the blobs in a container to email...

    Thanks in Advance..

    0 comments No comments

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.