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

Error with Microsoft graph, ODataType error with Sendmail

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

ServiceException: Code: RequestBodyRead Message: The property 'oDataType' does not exist on type microsoft.graph.itemBody'. Make sure to only use property names that are defined by the type or mark the type as open type.

我的代码主要是从微软示例中复制的。

  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();

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

谢谢

  • 我怀疑您使用的是旧版 library/build。我 remember the related issue 去年就修好了。
  • 请将其更新为最新版本,尝试对其进行测试,如果您仍然可以重现该问题,请告诉我们。