gpt4 book ai didi

microsoft-graph-api - 发送包含来自用户收件箱的不同邮件作为附件的新邮件

转载 作者:行者123 更新时间:2023-12-01 12:18:16 25 4
gpt4 key购买 nike

我正在开发一个 Multi-Tenancy 守护程序应用程序。应用程序需要代表用户发送电子邮件。应用程序发送的电子邮件必须包含来自用户收件箱的另一封电子邮件作为附件。

这可以通过简单地引用现有电子邮件的 id 而不是下载现有电子邮件的内容来实现吗?

我正在尝试下面这样的事情。使用 sendMail api 并尝试将现有电子邮件项目作为附件引用。但我收到此错误:

Cannot process input of abstract type Microsoft.OutlookServices.Item



我是在正确的方向吗?实现此用例的最佳方法是什么。

POST https://graph.microsoft.com/v1.0/me/sendMail HTTP/1.1
authorization: bearer {access_token}
content-type: application/json
content-length: 96

{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [{
"emailAddress": {
"address": "garthf@a830edad9050849NDA1.onmicrosoft.com"
}
}],
"attachments": [
"@odata.type": "#Microsoft.OutlookServices.ItemAttachment",
"name": "menu.txt",
"item": {
"id": "AAMkADBlOWNlOWExLTdjMzktNDI5NC04MDY3LTRiZGM2NTIxMzUyNABGAAAAAAC11nCh2QXMSJ7F766v_WCUBwBSt5DMAwrBRJGMMbg9jqoYAAAGNiHGAABSt5DMAwrBRJGMMbg9jqoYAAAJXgInAAA="
<!--This is the id of an existing email in User's inbox -->
}
]
},
"saveToSentItems": "false"
}

最佳答案

您不能只提供 id的消息。如果你这样做,你会得到一个空白的附件。不幸的是,API 没有设置为通过 ID 检索项目并为您插入。

那么这意味着您需要自己检索消息并将整个 JSON 负载包含在 item 中。附件的属性。 (见 https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/message_post_attachments)

您需要注意一个关键细节:在添加要附加的消息的 JSON 表示之前,您需要添加一个 @odata.type属性,并将其设置为 microsoft.graph.message .

例如:

获取要附加的消息

GET /me/messages/{id}

回复
{
"@odata.etag": "W/\"CQAAABYAAACImwNLdwWFR4SE3YBnGvEfAAAOjRuW\"",
"id": "AAMkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgBGAAAAAACUZXoWyqoWRohmHfOzvx9wBwCImwNLdwWFR4SE3YBnGvEfAAAAAAEMAACImwNLdwWFR4SE3YBnGvEfAAAOi7KdAAA=",
"createdDateTime": "2017-10-26T12:22:03Z",
"lastModifiedDateTime": "2017-10-26T12:22:03Z",
"changeKey": "CQAAABYAAACImwNLdwWFR4SE3YBnGvEfAAAOjRuW",
"categories": [],
"receivedDateTime": "2017-10-26T12:22:03Z",
"sentDateTime": "2017-10-26T12:22:02Z",
"hasAttachments": false,
"internetMessageId": "<BLUPR13MB0274245999AAD00105B87333A6450@BLUPR13MB0274.namprd13.prod.outlook.com>",
"subject": "Test attachment stuff",
"bodyPreview": "Hello world!",
"importance": "normal",
"parentFolderId": "AQMkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgAuAAADlGV6FsqqFkaIZh3zs78fcAEAiJsDS3cFhUeEhADdgGca8R8AAAIBDAAAAA==",
"conversationId": "AAQkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgAQAOcAXOsMKqFDlKHlkwvtP0Y=",
"isDeliveryReceiptRequested": false,
"isReadReceiptRequested": false,
"isRead": false,
"isDraft": false,
"webLink": "https://outlook.office365.com/owa/?ItemID=AAMkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgBGAAAAAACUZXoWyqoWRohmHfOzvx9wBwCImwNLdwWFR4SE3YBnGvEfAAAAAAEMAACImwNLdwWFR4SE3YBnGvEfAAAOi7KdAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"body": {
"contentType": "html",
"content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=iso-8859-1\">\r\n<style type=\"text/css\" style=\"display:none\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" dir=\"ltr\" style=\"font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif\">\r\n<p>Hello world!</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
},
"sender": {
"emailAddress": {
"name": "MOD Administrator",
"address": "admin@contoso.onmicrosoft.com"
}
},
"from": {
"emailAddress": {
"name": "MOD Administrator",
"address": "admin@contoso.onmicrosoft.com"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "Adele Vance",
"address": "AdeleV@contoso.onmicrosoft.com"
}
}
],
"ccRecipients": [],
"bccRecipients": [],
"replyTo": []
}

发送带有项目附件的新邮件

注意添加 "@odata.type": "microsoft.graph.message",item 中附加消息的 JSON 表示属性(property)。
POST /me/sendmail
Content-Type: application/json

{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [{
"emailAddress": {
"address": "adelev@contoso.onmicrosoft.com"
}
}],
"attachments": [
{
"@odata.type": "#microsoft.graph.itemAttachment",
"name": "Test attachment stuff",
"item": {
"@odata.type": "microsoft.graph.message",
"@odata.etag": "W/\"CQAAABYAAACImwNLdwWFR4SE3YBnGvEfAAAOjRuW\"",
"id": "AAMkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgBGAAAAAACUZXoWyqoWRohmHfOzvx9wBwCImwNLdwWFR4SE3YBnGvEfAAAAAAEMAACImwNLdwWFR4SE3YBnGvEfAAAOi7KdAAA=",
"createdDateTime": "2017-10-26T12:22:03Z",
"lastModifiedDateTime": "2017-10-26T12:22:03Z",
"changeKey": "CQAAABYAAACImwNLdwWFR4SE3YBnGvEfAAAOjRuW",
"categories": [],
"receivedDateTime": "2017-10-26T12:22:03Z",
"sentDateTime": "2017-10-26T12:22:02Z",
"hasAttachments": false,
"internetMessageId": "<BLUPR13MB0274245999AAD00105B87333A6450@BLUPR13MB0274.namprd13.prod.outlook.com>",
"subject": "Test attachment stuff",
"bodyPreview": "Hello world!",
"importance": "normal",
"parentFolderId": "AQMkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgAuAAADlGV6FsqqFkaIZh3zs78fcAEAiJsDS3cFhUeEhADdgGca8R8AAAIBDAAAAA==",
"conversationId": "AAQkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgAQAOcAXOsMKqFDlKHlkwvtP0Y=",
"isDeliveryReceiptRequested": false,
"isReadReceiptRequested": false,
"isRead": false,
"isDraft": false,
"webLink": "https://outlook.office365.com/owa/?ItemID=AAMkADRkOWJjMjdlLTM3OWMtNDU5ZS05YWZlLTRjMjkwZWE5NWMyYgBGAAAAAACUZXoWyqoWRohmHfOzvx9wBwCImwNLdwWFR4SE3YBnGvEfAAAAAAEMAACImwNLdwWFR4SE3YBnGvEfAAAOi7KdAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"body": {
"contentType": "html",
"content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=iso-8859-1\">\r\n<style type=\"text/css\" style=\"display:none\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" dir=\"ltr\" style=\"font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif\">\r\n<p>Hello world!</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
},
"sender": {
"emailAddress": {
"name": "MOD Administrator",
"address": "admin@contoso.onmicrosoft.com"
}
},
"from": {
"emailAddress": {
"name": "MOD Administrator",
"address": "admin@contoso.onmicrosoft.com"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "Adele Vance",
"address": "AdeleV@contoso.onmicrosoft.com"
}
}
],
"ccRecipients": [],
"bccRecipients": [],
"replyTo": []
}
}
]
},
"saveToSentItems": "false"
}

关于microsoft-graph-api - 发送包含来自用户收件箱的不同邮件作为附件的新邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46528376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com