当我使用 Outlook 客户端发送带有内嵌图像的邮件时。
html 电子邮件中的图像如下所示,其中包含cid:
<img size="100" src="cid:3bb599fc-f3eb-465b-af83-aa6a495f563a" style="max-width:100%">
当我使用
GET /me/messages/{messageId}/attachments
返回结果中的contentId与html 中的cid匹配。
{
"value": [
{
"@odata.type": "#microsoft.graph.fileAttachment",
"id": "aaa",
"lastModifiedDateTime": "2017-11-30T09:32:09Z",
"name": "image.png",
"contentType": "image/png",
"size": 100,
"isInline": true,
"contentId": "3bb599fc-f3eb-465b-af83-aa6a495f563a",
"contentLocation": null,
"contentBytes": "validBase64Bytes"
}
]
}
现在我正在尝试使用 Microsoft Graph API 添加内嵌图像。
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentBytes": "validBase64Bytes"
}
但是,contentId
返回的结果中为 null。
{
"@odata.type": "#microsoft.graph.fileAttachment",
"id": "aaa",
"lastModifiedDateTime": "2017-11-30T09:35:50Z",
"name": "1.jpg",
"contentType": "image/jpeg",
"size": 100,
"isInline": true,
"contentId": null,
"contentLocation": null,
"contentBytes": "validBase64Bytes"
}
如果我contentId
在 POST 中手动设置
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentId": "myContentId",
"contentBytes": "validBase64Bytes"
}
它会返回错误
{
"error": {
"code": "BadRequest",
"message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",
"innerError": {
"request-id": "36e95f0a-ad75-46c6-b86c-d585a150b96d",
"date": "2017-11-30T09:37:41"
}
}
}
那么如何正确添加内嵌图片呢?
奇怪的是,我再次尝试运行完全相同的代码,它现在不会给我任何错误。
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentId": "myContentId",
"contentBytes": "validBase64Bytes"
}
不知道是不是暂时的问题。我会通知微软团队检查日志。
如果我对如何使用 API 有错误,请务必指出。谢谢。
我将把它留在这里供以后的人节省一些时间来实现添加内联图像。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句