exception of type 'microsoft.graph.models.odata errors.odata error' was thrown.'

Hattikoti, Roopa S 20 Reputation points
2023-08-09T05:46:11.8066667+00:00
if (!string.IsNullOrEmpty(status))
  {
    var request = new Microsoft.Graph.Me.Messages.Item.Forward.ForwardPostRequestBody
      {
        Comment = "comment-value",
        ToRecipients = new List<Recipient>
         {
           new Recipient
             {
               EmailAddress = new EmailAddress
                 {
                    Name = "name-value",
                    Address = "******@dell.com",
                  },
               },
              },
         };
 await graphClient.Me.Messages[mes.Id].Forward.PostAsync(request);
   }

          }
       catch (Exception ex)
          {
            Console.WriteLine("Error:" + ex.ToString());
          }


I am converting generic mailboxes to exchange online. I am doing some operation and then forwarding that mail to another mail.

I have Mail.ReadWrite and Mail.Send API permissions. But still getting exception of type 'microsoft.graph.models.odata errors.odata error' was thrown.'. Please suggest me on this.

Don't have User.Read permission is that causing me an issue.

if (!string.IsNullOrEmpty(status))
                                            {
                                                var request = new Microsoft.Graph.Me.Messages.Item.Forward.ForwardPostRequestBody
                                                {
                                                    Comment = "comment-value",
                                                    ToRecipients = new List<Recipient>
                                                        {
                                                            new Recipient
                                                            {
                                                                EmailAddress = new EmailAddress
                                                                {
                                                                    Name = "name-value",
                                                                    Address = "******@dell.com",
                                                                },
                                                            },
                                                        },
                                                };
                                                await graphClient.Me.Messages[mes.Id].Forward.PostAsync(request);
                                            }

                                        }
                                        catch (Exception ex)
                                        {
                                            Console.WriteLine("Error:" + ex.ToString());
                                        }
Outlook | Windows | Classic Outlook for Windows | For business
Microsoft Security | Microsoft Graph
Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,376 Reputation points
    2023-08-09T08:31:40.8033333+00:00

    Hi @Hattikoti, Roopa S

    I can't find the problem from the type of exception you shared, you should catch the error message to analyze the problem details.

    Please refer to my code snippet:

    try {
        var requestBody = new Microsoft.Graph.Me.Messages.Item.Forward.ForwardPostRequestBody
        {
            Comment = "comment-value",
            ToRecipients = new List<Recipient>
        {
            new Recipient
            {
                EmailAddress = new EmailAddress
                {
                    Name = "name-value",
                    Address = "address-value",
                },
            },
        },
        };
        await graphClient.Me.Messages["{message id}"].Forward.PostAsync(requestBody);
    }
    catch (ODataError odataError)
    {
    
        Console.WriteLine(odataError.Error.Code);
        Console.WriteLine("Error Message: " + odataError.Error.Message);
    
    }
    

    4 (002)

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.