在Logic Apps中使用Graph API托管身份发送带附件邮件遇阻
解决Logic Apps中Graph API发送带附件邮件的错误
问题根源
你把attachments属性错误嵌套在了toRecipients的收件人对象里,根据Graph API规范,attachments是message对象的直接属性,不属于microsoft.graph.recipient类型,这就是报错的核心原因。
修正后的请求Body
调整结构,将attachments数组移到message对象下,与body、subject同级。同时注意两个关键细节:
attachments是数组类型,支持添加多个附件contentBytes必须传入Base64编码后的文件内容,需要对Get_file_content的结果做Base64转换
{ "message": { "body": { "content": "Sending test file.", "contentType": "HTML" }, "ccRecipients": [ { "emailAddress": { "address": "d@blabla.com" } } ], "subject": "New files", "toRecipients": [ { "emailAddress": { "address": "d@blabla.com" } } ], "attachments": [ { "contentBytes": "@{base64(body('Get_file_content'))}", "contentType": "text/plain", "name": "@{items('For_each')?['Name']}", "odata.type": "#microsoft.graph.fileAttachment" } ] }, "saveToSentItems": "false" }
额外注意事项
- 若遍历多个文件添加附件,建议先用
Append to array variable动作收集所有附件对象,再将整个数组传入attachments字段 - 确认Base64转换逻辑正确,避免因编码错误导致附件无法正常打开
内容的提问来源于stack exchange,提问作者Mycha
相关产品推荐
相关产品推荐

