【问题标题】:'Send an Email' parameter 'attachment content' cannot be null“发送电子邮件”参数“附件内容”不能为空
【发布时间】:2021-10-21 23:10:59
【问题描述】:

我正在创建一个 Azure 逻辑应用程序以通过电子邮件发送包含数据的 CSV 文件。当没有数据时,Send_an_email_(V2) 步骤失败,我在其输出中看到以下错误:

Parameter 'Attachment Content' cannot be null or empty.

Azure 逻辑应用中的 Send_an_email_(V2) 操作从前面的 Create_CSV_table 操作的输出中获取部分输入。它使用Create_CSV_table 输出的body 如下所示,以便为电子邮件附件构造ContentBytes

    "actions": {
        "Create_CSV_table": {
            "inputs": {
                "format": "CSV",
                "from": "@body('Parse_JSON')"
            },
            "runAfter": {
                "Parse_JSON": [
                    "Succeeded"
                ]
            },
            "type": "Table"
        },
        "Send_an_email_(V2)": {
            "inputs": {
                "body": {
                    "Attachments": [
                        {
                            "ContentBytes": "@{base64(body('Create_CSV_table'))}",
                            "Name": "report.csv"
                        }
                    ],
                    "Body": "<p></p>",
                    "Subject": "My Report",
                    "To": "me@email.com"
                },
                "host": {
                    "connection": {
                        "name": "@parameters('$connections')['office365']['connectionId']"
                    }
                },
                "method": "post",
                "path": "/v2/Mail"
            },
            "runAfter": {
                "Create_CSV_table": [
                    "Succeeded"
                ]
            },
            "type": "ApiConnection"
        }

Create_CSV_table 步骤没有数据输入时,Create_CSV_table 步骤成功,Create_CSV_table 步骤的原始输出显示空正文如下:

{
    "body": ""
}

失败的 Send_an_email_(V2) 步骤的原始输入

{
    HTTP stuff ...,
    "body": {
        "Attachments": [
            {
                "ContentBytes": "",
                "Name": "report.csv"
            }
        ],
        "Body": "<p></p>",
        "Subject": "Report",
        "To": "me@mail.com"
    }
}

失败的 Send_an_email_(V2) 步骤的原始输出

{
    HTTP stuff ...,
    "body": {
        "status": 400,
        "message": "Parameter 'Attachment Content' cannot be null or empty.\r\nclientRequestId: 887e3968-c7e9-4c35-b588-f76fd0e51545",
        "error": {
            "message": "Parameter 'Attachment Content' cannot be null or empty."
        },
        "source": "office365-ase.azconn-ase.p.azurewebsites.net"
    }
}

我该如何处理?我是否需要为Send_an_email_(V2) 输入的"ContentBytes" 实现自己的空处理?如果是这样,我该怎么做?或者有没有其他方法来处理这个问题。我希望在没有 CSV 内容时发送空电子邮件。

我发现 @{base64(body('Create_CSV_table'))} 是一个 Azure 逻辑应用程序 expression(由 @ 表示),其中包含作用于 body 的 JSON 的函数,用于 Create_CSV_table 的输出以及封闭的 @ 987654341@ 导致表达式的输出为字符串。

【问题讨论】:

  • 这是因为Send an Email (V2)连接器i.imgur.com/fMs8MDb.png的附件内容中没有添加任何内容
  • 嗨@SwethaKandikonda-MT 这不是问题。我已经在问题中详细解释了这个问题;)

标签: azure-logic-apps


【解决方案1】:

在最后一步之后,您可以使用带有 .csv 文件扩展名的 Create blob(V2) 连接发送到存储帐户,然后使用 Get blob content(V2) 连接发送相同的 blob 内容,然后发送电子邮件。

这是 LogicApp 的截图

展望:

这是工作流程

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Create_CSV_table_2": {
                "inputs": {
                    "format": "CSV",
                    "from": "@variables('Array')"
                },
                "runAfter": {
                    "For_each_2": [
                        "Succeeded"
                    ]
                },
                "type": "Table"
            },
            "Create_blob_(V2)": {
                "inputs": {
                    "body": "@body('Create_CSV_table_2')",
                    "headers": {
                        "ReadFileMetadataFromServer": true
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files",
                    "queries": {
                        "folderPath": "/ch1container2408",
                        "name": "TestSample1.csv",
                        "queryParametersSingleEncoded": true
                    }
                },
                "runAfter": {
                    "Create_CSV_table_2": [
                        "Succeeded"
                    ]
                },
                "runtimeConfiguration": {
                    "contentTransfer": {
                        "transferMode": "Chunked"
                    }
                },
                "type": "ApiConnection"
            },
            "For_each_2": {
                "actions": {
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "Array",
                            "value": {
                                "created_at": "@items('For_each_2')['created_at']",
                                "funds": "@items('For_each_2')['funds']",
                                "id": "@items('For_each_2')['id']",
                                "pair": "@items('For_each_2')['market']",
                                "price": "@items('For_each_2')['price']",
                                "side": "@items('For_each_2')['side']",
                                "volume": "@items('For_each_2')['volume']"
                            }
                        },
                        "runAfter": {},
                        "type": "AppendToArrayVariable"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Initialize_variable_2": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Get_blob_content_(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent('/<Your Container>','/<Your File>.csv'))}/content",
                    "queries": {
                        "inferContentType": true
                    }
                },
                "runAfter": {
                    "Create_blob_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            },
            "HTTP": {
                "inputs": {
                    "method": "GET",
                    "uri": "https://api.wazirx.com/api/v2/trades?market=btcusdt"
                },
                "runAfter": {},
                "type": "Http"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Array",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Table",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@body('HTTP')",
                    "schema": {
                        "items": {
                            "properties": {
                                "created_at": {
                                    "type": "string"
                                },
                                "funds": {
                                    "type": "string"
                                },
                                "id": {
                                    "type": "integer"
                                },
                                "market": {
                                    "type": "string"
                                },
                                "price": {
                                    "type": "string"
                                },
                                "side": {},
                                "volume": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "id",
                                "market",
                                "price",
                                "volume",
                                "funds",
                                "created_at",
                                "side"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {
                    "HTTP": [
                        "Succeeded"
                    ]
                },
                "type": "ParseJson"
            },
            "Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Attachments": [
                            {
                                "ContentBytes": "@{base64(body('Get_blob_content_(V2)'))}",
                                "Name": "@body('Create_blob_(V2)')?['Name']"
                            }
                        ],
                        "Body": "<p>TABLE TEST</p>",
                        "Subject": "Test",
                        "To": "<To Address>"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/Mail"
                },
                "runAfter": {
                    "Get_blob_content_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {},
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob": {
                    "connectionId": "<Your  ConnectionId>",
                    "connectionName": "azureblob",
                    "id": "<Id>"
                },
                "office365": {
                    "connectionId": "<Your  ConnectionId>",
                    "connectionName": "office365",
                    "id": "<Your Id>"
                }
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-29
    • 2023-03-10
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 2015-03-10
    • 2016-11-30
    相关资源
    最近更新 更多