1
votes

Accessing email via Microsoft Graph Api, I have added Single Valued Properties to the Message object. But while executing the SendMail query: client.Users[MailBoxId].SendMail(message, true).Request().PostAsync(); It is throwing an error which states- Code: RequestBodyRead Message: The annotation 'odata.context' was found. This annotation is either not recognized or not expected at the current position. Inner error: AdditionalData: date: 2020-07-24T07:46:37 request-id: xxxx-xxx-xxx-xxx-xxxxx ClientRequestId: xxxx-xxx-xxx-xxx-xxxxx. https://graph.microsoft.com/v1.0/$metadata#users('[email protected]')/messages(singleValueExtendedProperties())/$entity. In this picture we can see the Odata values Any leads in solving this will be very helpful.

1

1 Answers

0
votes

Ran into a similar problem when creating a draft message first using AddAsync() and then sending the message using SendMail().PostAsync(). It was resulting in the following exception: Message: Code: RequestBodyRead Message: The annotation 'odata.context' was found. This annotation is either not recognized or not expected at the current position.

I replaced the SendMail().PostAsync() with Send().PostAsync() and the problem was resolved. Code snippet below

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