msgraph-sdk-java: Can no longer send "saved" emails (v2.2.0 and higher)
Expected behavior
My current library is sending emails by first creating a “saved” message by creating a new Message object, populating it, and calling .messages().buildRequest().post()
. That works fine and I can see the email show up in my drafts folder with the correct info. However when I try sending that email by calling sendMail({Message obj}, true).buildRequest().post()
it fails with the error posted below. I’ve tried with and without adding attachments to the message first. In version 2.1.0 this worked as expected and did not error (I just tested it minutes ago) but 2.2.0 and 2.3.0 both give me the context error. Maybe something changed with how you send emails in the later versions and I just need to do it differently? But I do need to “save” it first because I have a lot of attachments I’m adding to the email before it’s sent off. If you need anything else just let me know. Also if you have an easy workaround I would also appreciate it as I’m rushing to get everything finished before the basic auth termination coming up in a few weeks.
Actual behavior
I tried getting the response when it worked but was having issues getting the library to log that, even though I set the logging level to debug.
Request
POST https://graph.microsoft.com/v1.0/me/microsoft.graph.sendMail
SdkVersion : graph-java/v2.3.0
Authorization : [PII_REDACTED]
{
"saveToSentItems": true,
"message": {
"bccRecipients": [],
"body": {
"content": "",
"contentType": "text"
},
"bodyPreview": "",
"ccRecipients": [],
"conversationId": "-",
"conversationIndex": "-",
"flag": {
"flagStatus": "notFlagged"
},
"hasAttachments": false,
"importance": "normal",
"inferenceClassification": "focused",
"internetMessageId": "-",
"isDeliveryReceiptRequested": false,
"isDraft": true,
"isRead": true,
"isReadReceiptRequested": false,
"parentFolderId": "-",
"receivedDateTime": "2020-10-05T22:11:16.000Z",
"replyTo": [],
"sentDateTime": "2020-10-05T22:11:16.000Z",
"subject": "subject",
"toRecipients": [
{
"emailAddress": {
"address": "addr",
"name": "name"
}
}
],
"webLink": "https://outlook.office365.com/owa/?ItemID=-&exvsurl=1&viewmodel=ReadMessageItem",
"categories": [],
"changeKey": "-",
"createdDateTime": "2020-10-05T22:11:16.000Z",
"lastModifiedDateTime": "2020-10-05T22:11:16.000Z",
"id": "-",
"@odata.etag": "-",
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('-')/messages/$entity"
}
}
Response
400 : Bad Request
Cache-Control : private
client-request-id : -
Content-Length : 392
Content-Type : application/json
Date : Mon, 05 Oct 2020 22:11:16 GMT
request-id : -
Strict-Transport-Security : max-age=31536000
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Central US","Slice":"SliceC","Ring":"2","ScaleUnit":"000","RoleInstance":"AGSFE_IN_1"}}
{
"error": {
"code": "RequestBodyRead",
"message": "The annotation \u0027odata.context\u0027 was found. This annotation is either not recognized or not expected at the current position.",
"innerError": {
"date": "2020-10-05T22:11:16",
"request-id": "-",
"client-request-id": "-"
}
}
}
Steps to reproduce the behavior
See expected behavior
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (9 by maintainers)
Ah okay… so basically a fluke it used to work the old way. Just tried it and it worked great! Thank you very much!