使用逻辑应用程序将文件附件从 Ms Forms 传递到 Outlook

Pass file attachments from Ms Forms to Outlook using Logic apps

我有一个连接到 Ms Forms 并将结果作为电子邮件发送的逻辑应用程序。 用户可以将文件上传到 Ms Forms。我不知道用户将上传多少文件(可能为零),也不知道这些文件的扩展名。 如何将这些文件作为附件添加到逻辑应用发送的电子邮件中? 我正在将此连接器用于 MsForms。 https://docs.microsoft.com/en-us/connectors/microsoftforms/

这是您可以尝试的解决方法之一。

在使用触发器和 Get response details 连接器添加附件后,我使用 Compose 连接器来获取用户通过 MS Forms 上传的文件。

撰写表达式: json(body('Get_response_details_2')?['r13237ad0c60f42989d7ea61d8fee6482'])

然后我使用 For_each 循环从上一步组合连接器中检索文件。在接下来的步骤中,我使用一个驱动器的 Get file content 连接器。由于每个文件都将使用唯一的 ID 保存,因此我过去常常检索文件内容并将其传递给 Send the email.

这是我的逻辑应用程序的代码视图

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@json(body('Get_response_details_2')?['r13237ad0c60f42989d7ea61d8fee6482'])",
                "runAfter": {
                    "Get_response_details_2": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "For_each_2": {
                "actions": {
                    "Get_file_content_2": {
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['onedriveforbusiness']['connectionId']"
                                }
                            },
                            "method": "get",
                            "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(item()?['id']))}/content"
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    },
                    "Send_an_email_(V2)": {
                        "inputs": {
                            "body": {
                                "Attachments": [
                                    {
                                        "ContentBytes": "@{base64(body('Get_file_content_2'))}",
                                        "Name": "@{item()?['id']}"
                                    }
                                ],
                                "Body": "<p>My Files as Attachment</p>",
                                "Subject": "Sample Flow",
                                "To": "v-swethaka@microsoft.com"
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['office365']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/v2/Mail"
                        },
                        "runAfter": {
                            "Get_file_content_2": [
                                "Succeeded"
                            ]
                        },
                        "type": "ApiConnection"
                    }
                },
                "foreach": "@outputs('Compose')",
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Get_response_details_2": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['microsoftforms']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/formapi/api/forms('@{encodeURIComponent('v4j5cvGGr0GRqy180BHbR8k7o6rhlmJKk_S4R3vq7DZUQjM1VU5ONE1SRTNXVkI2N0pJTFVQM1gzMS4u')}')/responses",
                    "queries": {
                        "response_id": "@triggerBody()?['resourceData']?['responseId']"
                    }
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_new_response_is_submitted": {
                "inputs": {
                    "body": {
                        "eventType": "responseAdded",
                        "notificationUrl": "@{listCallbackUrl()}",
                        "source": "ms-connector"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['microsoftforms']['connectionId']"
                        }
                    },
                    "path": "/formapi/api/forms/@{encodeURIComponent('v4j5cvGGr0GRqy180BHbR8k7o6rhlmJKk_S4R3vq7DZUQjM1VU5ONE1SRTNXVkI2N0pJTFVQM1gzMS4u')}/webhooks"
                },
                "splitOn": "@triggerBody()?['value']",
                "type": "ApiConnectionWebhook"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "microsoftforms": {
                    "connectionId": "/subscriptions/<Your Subscription Id>/resourceGroups/<Your Resource group>/providers/Microsoft.Web/connections/microsoftforms",
                    "connectionName": "microsoftforms",
                    "id": "/subscriptions/b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f/providers/Microsoft.Web/locations/northcentralus/managedApis/microsoftforms"
                },
                "office365": {
                    "connectionId": "/subscriptions/<Your Subscription Id>/resourceGroups/<Your Resource group>/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/<Your Subscription Id>/providers/Microsoft.Web/locations/northcentralus/managedApis/office365"
                },
                "onedriveforbusiness": {
                    "connectionId": "/subscriptions/<Your Subscription Id>/resourceGroups/<Your Resource group>/providers/Microsoft.Web/connections/onedriveforbusiness",
                    "connectionName": "onedriveforbusiness",
                    "id": "/subscriptions/<Your Subscription Id>/providers/Microsoft.Web/locations/northcentralus/managedApis/onedriveforbusiness"
                }
            }
        }
    }
}

注意:- 这会导致流程有多个电子邮件(即此人上传的文件数)。

触发一次 一种解决方法是将所有这些链接保存在一个数组变量中并将其发送到电子邮件,否则您也可以关注 How to send only one email with multiple attachments.