json Microsoft.Graph发送带有内联图像的电子邮件,不显示内联图像,而是显示为附件

pkwftd7m  于 2023-05-19  发布在  其他
关注(0)|答案(1)|浏览(189)

我们的应用程序发送电子邮件进行确认等。以前使用SMTP。我们设置了链接资源的邮件,它显示的图像内联刚刚好。
现在有一个客户端切换到了Azure,所以我添加了通过Azure发送电子邮件的代码。邮件被发送和接收,但内嵌图像不显示在正文中。它作为一个附件在那里,我不想看到它。
这是我的SendMailPostRequestBody(为了阅读而序列化):

{
      "AdditionalData": {},
      "BackingStore": {
        "ReturnOnlyChangedValues": false,
        "InitializationCompleted": true
      },
      "Message": {
        "Attachments": [{
                "ContentType": "text/plain",
                "IsInline": false,
                "LastModifiedDateTime": null,
                "Name": "file1.PDF",
                "Size": null,
                "AdditionalData": {
                    "ContentBytes": {
                        "ValueKind": 3
                    }
                },
                "BackingStore": {
                    "ReturnOnlyChangedValues": false,
                    "InitializationCompleted": true
                },
                "Id": "file1.PDF",
                "OdataType": "#microsoft.graph.fileAttachment"
            }, {
                "ContentType": "text/plain",
                "IsInline": false,
                "LastModifiedDateTime": null,
                "Name": "file2.pdf",
                "Size": null,
                "AdditionalData": {
                    "ContentBytes": {
                        "ValueKind": 3
                    }
                },
                "BackingStore": {
                    "ReturnOnlyChangedValues": false,
                    "InitializationCompleted": true
                },
                "Id": "file2.pdf",
                "OdataType": "#microsoft.graph.fileAttachment"
            }, {
                "ContentType": "image/jpeg",
                "IsInline": true,
                "LastModifiedDateTime": null,
                "Name": "Logo.jpg",
                "Size": null,
                "AdditionalData": {
                    "ContentBytes": {
                        "ValueKind": 3
                    }
                },
                "BackingStore": {
                    "ReturnOnlyChangedValues": false,
                    "InitializationCompleted": true
                },
                "Id": "Logojpg",
                "OdataType": "#microsoft.graph.fileAttachment"
            }
        ],
        "BccRecipients": null,
        "Body": {
            "AdditionalData": {},
            "BackingStore": {
                "ReturnOnlyChangedValues": false,
                "InitializationCompleted": true
            },
            "Content": "<html>\t<body>\t\t<table cellspacing=\"0\" cellpadding=\"0\" class=\"mailimage mailimage1\"><tbody><tr><td><img src=\"cid:Logojpg\" alt=\"Logojpg\" ></td></tr></tbody></table></body></html>    ",
            "ContentType": 1,
            "OdataType": null
        },
        "BodyPreview": null,
        "CcRecipients": [],
        "ConversationId": null,
        "ConversationIndex": null,
        "Extensions": null,
        "Flag": null,
        "From": {
            "AdditionalData": {},
            "BackingStore": {
                "ReturnOnlyChangedValues": false,
                "InitializationCompleted": true
            },
            "EmailAddress": {
                "AdditionalData": {},
                "Address": "info@client.nl",
                "BackingStore": {
                    "ReturnOnlyChangedValues": false,
                    "InitializationCompleted": true
                },
                "Name": null,
                "OdataType": null
            },
            "OdataType": null
        },
        "HasAttachments": null,
        "Importance": null,
        "InferenceClassification": null,
        "InternetMessageHeaders": null,
        "InternetMessageId": null,
        "IsDeliveryReceiptRequested": null,
        "IsDraft": null,
        "IsRead": null,
        "IsReadReceiptRequested": null,
        "MultiValueExtendedProperties": null,
        "ParentFolderId": null,
        "ReceivedDateTime": null,
        "ReplyTo": null,
        "Sender": {
            "AdditionalData": {},
            "BackingStore": {
                "ReturnOnlyChangedValues": false,
                "InitializationCompleted": true
            },
            "EmailAddress": {
                "AdditionalData": {},
                "Address": "info@client.nl",
                "BackingStore": {
                    "ReturnOnlyChangedValues": false,
                    "InitializationCompleted": true
                },
                "Name": null,
                "OdataType": null
            },
            "OdataType": null
        },
        "SentDateTime": null,
        "SingleValueExtendedProperties": null,
        "Subject": "refnr 00412/16818 *** DEMO ***",
        "ToRecipients": [{
                "AdditionalData": {},
                "BackingStore": {
                    "ReturnOnlyChangedValues": false,
                    "InitializationCompleted": true
                },
                "EmailAddress": {
                    "AdditionalData": {},
                    "Address": "my@mail.nl",
                    "BackingStore": {
                        "ReturnOnlyChangedValues": false,
                        "InitializationCompleted": true
                    },
                    "Name": null,
                    "OdataType": null
                },
                "OdataType": null
            }
        ],
        "UniqueBody": null,
        "WebLink": null,
        "Categories": null,
        "ChangeKey": null,
        "CreatedDateTime": null,
        "LastModifiedDateTime": null,
        "AdditionalData": {},
        "BackingStore": {
            "ReturnOnlyChangedValues": false,
            "InitializationCompleted": true
        },
        "Id": null,
        "OdataType": "#microsoft.graph.message"
    },
    "SaveToSentItems": false
    }

我收到了电子邮件,它有三个附件。其中之一就是形象。我希望这一个不是可见的附件时,显示在体内内联。
contentBytes不显示它,但其中有一个base64字符串。我可以在outlook中打开邮件中的附件。
为什么图像没有显示在身体里?

mzmfm0qo

mzmfm0qo1#

我想明白了
显然,您必须将“ContentId”添加到附件的AdditionalData字典中。
因此,对于用于显示内联图像的附件,addtionaldata字典应该如下所示:

"AdditionalData": {
            "ContentBytes": "the-base64-bytes-string",
            "ContentId": "the-id-used-in-the-img-src"
        }

然后oulook将能够显示图像。

相关问题