我通过Microsoft Graph Api访问电子邮件,已向消息对象添加了单值属性。但是在执行SendMail查询时:client.Users[MailBoxId].SendMail(message, true).Request().PostAsync();
抛出了一个错误,指出-代码:RequestBodyRead
消息:找到注释“ odata.context”。在当前位置无法识别或不期望该注释。
内部错误:
附加数据:
日期:2020-07-24T07:46:37
要求编号:xxxx-xxx-xxx-xxx-xxxxx
ClientRequestId:xxxx-xxx-xxx-xxx-xxxxx。
https://graph.microsoft.com/v1.0/$metadata#users('xxx@y.com')/messages(singleValueExtendedProperties())/$entity。
In this picture we can see the Odata values
解决这一问题的任何线索都将非常有帮助。
答案 0 :(得分:0)
首先使用AddAsync()创建草稿消息,然后使用SendMail()。PostAsync()发送消息时遇到类似的问题。这导致了以下异常: 消息:代码:RequestBodyRead消息:找到注释'odata.context'。该注释在当前位置无法识别或无法预期。
我用Send()。PostAsync()替换了SendMail()。PostAsync(),问题已解决。下面的代码段
//Construct the Email Message
var emailMessage = new Message
{
Subject = emailSubject,
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = emailBody
},
ToRecipients = toEmailList,
CcRecipients = ccEmailList,
BccRecipients = bccEmailList,
};
//Create a draft message
var draftEmailMessage = await graphClient.Users[emailId].Messages
.Request()
.AddAsync(emailMessage);
//Code to add attachments to the draft message
....
//Send the email message
// NOTE: This does NOT work, throws Odata.context error
/*
await graphClient.Users[emailId].SendMail(draftEmailMessage, true)
.Request()
.PostAsync();
*/
// NOTE: Replaced above commented code with this - works perfectly!
await graphClient.Users[emailId].Messages[draftEmailMessage.Id].Send()
.Request()
.PostAsync();