【问题标题】:Send Email with multiple attachment using Azure Logic App使用 Azure 逻辑应用发送带有多个附件的电子邮件
【发布时间】:2022-01-19 17:48:56
【问题描述】:

我需要将上传到我的 Azure 存储容器的 Blob 作为附件发送。上传到容器的文件数量会发生变化,因此我需要使用动态方法进行附件。 I have verified this question related to it

我正在使用以下逻辑:

附加到变量值

{

"Name": items('For_each')?['DisplayName']
"ContentBytes":body('Get_blob_content')

} 当我尝试保存逻辑时,出现以下错误:

Save logic app failed
Failed to save logic app testing. The template validation failed: 'The action(s) 'Get_blob_content' referenced by 'inputs' in action 'Append_to_array_variable' are not defined in the template.'.

我该如何解决这个问题?

【问题讨论】:

  • 按照上述共享步骤,我们创建了一个工作流并在我们的本地环境中进行了测试,工作正常这是screen shot供您参考:我们在@987654331中使用了相同的逻辑@& 能够保存逻辑应用程序,如 GIF 所示。
  • 相反,一次保存整个工作流建议您在每个阶段或 appendtoarray 变量阶段和发布之前保存逻辑应用程序,然后将值附加到具有前一阶段输出的附件变量。
  • @VenkateshDodda-MT:谢谢。它在 for 循环中给出错误 imgur.com/a/lQ3SSd9。在 Get Blob content inside loop 中,我如何提及 blob ?我们是否需要从 List Blob 或第一个触发器(上传 lob 时)中获取参考。抱歉,我是新手,对此感到困惑
  • 请参考 blob 路径,从列表中的 blob 操作仅在获取 blob 内容操作中,如 image 所示
  • 对于内容变量“Content”,请使用下面的表达式:base64(body('Get_blob_content_(V2)')) 在追加到数组变量块中,如下图所示`i.stack.imgur.com/vI7kP.png

标签: azure azure-logic-apps


【解决方案1】:

根据上面共享的错误消息,建议您在每个阶段或 appendtoarray 变量阶段和发布之前保存逻辑应用程序,而不是一次保存整个工作流,然后将值附加到前一阶段的附件变量输出。

基于上述要求,我们在本地环境中创建了以下逻辑应用程序并对其进行了测试,效果很好。

在我们的工作流程中,我们使用 For Each 循环来自 List Blobs 操作的 blob。在 For Each 中,您可以使用 Get blob content 获取 blob 内容,然后使用 Append to array variable 添加附件。

Name 和 ContentBytes 表达式如下:

 "ContentBytes": "@base64(body('Get_blob_content_(V2)'))",
 "Name": "@items('For_each')?['DisplayName']"

这是我们创建的 Logic 应用的代码视图:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "attachments",
                            "value": {
                                "ContentBytes": "@base64(body('Get_blob_content_(V2)'))",
                                "Name": "@items('For_each')?['DisplayName']"
                            }
                        },
                        "runAfter": {
                            "Get_blob_content_(V2)": [
                                "Succeeded"
                            ]
                        },
                        "type": "AppendToArrayVariable"
                    },
                    "Get_blob_content_(V2)": {
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                }
                            },
                            "method": "get",
                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent(items('For_each')?['Path']))}/content",
                            "queries": {
                                "inferContentType": true
                            }
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "foreach": "@body('Lists_blobs_(V2)')?['value']",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "attachments",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Lists_blobs_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Lists_blobs_(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent('JTJmcmVwb3J0cw=='))}",
                    "queries": {
                        "nextPageMarker": "",
                        "useFlatListing": false
                    }
                },
                "metadata": {
                    "JTJmcmVwb3J0cw==": "/reports"
                },
                "runAfter": {},
                "type": "ApiConnection"
            },
            "Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Attachments": "@variables('attachments')",
                        "Body": "<p>tested logic app flow successfully</p>",
                        "Subject": "blob test",
                        "To": "<username>@microsoft.com"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/Mail"
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_blob_is_added_or_modified_(properties_only)_(V2)": {
                "evaluatedRecurrence": {
                    "frequency": "Minute",
                    "interval": 1
                },
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/triggers/batch/onupdatedfile",
                    "queries": {
                        "checkBothCreatedAndModifiedDateTime": false,
                        "folderId": "JTJmcmVwb3J0cw==",
                        "maxFileCount": 10
                    }
                },
                "metadata": {
                    "JTJmcmVwb3J0cw==": "/reports"
                },
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 1
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnection"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob": {
                    "connectionId": "/subscriptions/<sub-ID>/resourceGroups/<resourceGroup>/providers/Microsoft.Web/connections/azureblob",
                    "connectionName": "azureblob",
                    "id": "/subscriptions/<sub-id>/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
                },
                "office365": {
                    "connectionId": "/subscriptions/<sub-id>/resourceGroups/<resroucegroup>/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/<sub-id>/providers/Microsoft.Web/locations/eastus/managedApis/office365"
                }
            }
        }
    }
}

这是示例输出供参考:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    相关资源
    最近更新 更多