azure - 使用Azure逻辑应用程序发送带有多个附件的电子邮件

标签 azure azure-logic-apps

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

我正在使用以下逻辑:

enter image description here

附加到变量值

{

"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.'.

我该如何解决这个问题?

最佳答案

根据上面共享的错误消息,建议您在每个阶段或在 appendtoarray 变量 stage & post 之前保存逻辑应用,而不是立即保存整个工作流,然后将值附加到带有前一阶段输出的附件变量。

根据上述要求,我们在本地环境中创建了以下逻辑应用并对其进行了测试,运行良好。

在我们的工作流程中,我们使用 For Each 来循环 List Blobs 操作中的 Blob。在 For Each 中,您可以使用获取 blob 内容来获取 blob 内容,然后使用追加到数组变量来追加附件。

表达式Name和ContentBytes如下:

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

enter image description here

这是我们创建的逻辑应用的代码 View :

{
    "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"
                }
            }
        }
    }
}

这是供引用的示例输出:

enter image description here

关于azure - 使用Azure逻辑应用程序发送带有多个附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70382378/

相关文章:

php - Azure:使用存储模拟器时的帐户名和访问 key 是什么?

asp.net - 我可以更改逻辑应用的 Aspnet 版本吗?

azure-logic-apps - 逻辑应用程序 - 如何链接到运行

azure - 如何以编程方式创建 MS Flow/Azure Logic App 连接?

azure - Azure 逻辑应用中服务总线连接器的消息处理策略

azure - 从 LogicApp 使用 "Send a HTTP Request to DevOps"时获取身份验证错误

c# - 已发布的 Azure Web 角色中 CSS 图标生成的内容出现问题

azure - 如果我有自定义 STS,我是否需要联合身份验证?如果是这样,为什么?

Azure AD、B2B 和 Shibboleth 集成

azure - 在 Azure 中配置容器应用程序失败并出现 "Conflict"的合理原因是什么?为什么没有日志写入分析工作区?