Microsoft图形出错,Sendmail出现ODataType错误



我出现了一个错误,似乎找不到任何相关信息。当我运行代码时,会出现以下错误。我没有设置oDataType,所以我认为这是由api本身完成的。

ServiceException:代码:RequestBodyRead消息:类型microsoft.graph.itemBody'上不存在属性"oDataType"。请确保仅使用该类型定义的属性名称,或将该类型标记为打开类型。

我的代码大多是从微软的示例中复制的。

var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri(authority))
.Build();
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
client = new GraphServiceClient(authenticationProvider);
var message = new Microsoft.Graph.Message()
{
Subject = "Test email",
Body = new ItemBody
{
ContentType = BodyType.Text,                 
Content = "Test email."                    
},
HasAttachments = false,
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "myemail@mydomain.com"
}
}
}
};

var saveToSentItems = false;
await client.Users[userID].SendMail(message, saveToSentItems).Request().PostAsync();

如有任何帮助,我们将不胜感激。

谢谢

  • 我怀疑您使用的是较旧的库/构建。我记得相关的问题,去年就已经解决了
  • 请用最新的更新它,尝试测试同样的问题,并让我们知道你是否仍然可以重新解决这个问题

最新更新