I'm trying to reply an email on an outlook account. But when I try to create the reply (not send it, yet) I get the following exception:
ServiceException: Code: RequestBroker--ParseUri
Message: Resource not found for the segment 'microsoft.graph.createReply'.
Obviously, the problem is in the Url but doesn't make sense because, when I try to get the message before creating the reply, everything works except when I try to create the reply for that message.
This is the code:
ConfidentialClientApplication cca = new ConfidentialClientApplication(
[client_id], [redirect_uri],
new ClientCredential([secret]),
new TokenCache(), null);
string[] scopes = new string[]
{
"email",
"https://outlook.office.com/mail.read",
"https://outlook.office.com/mail.read.shared",
"https://outlook.office.com/mail.readwrite",
"https://outlook.office.com/mail.readwrite.shared",
"https://outlook.office.com/mail.send",
"https://outlook.office.com/mail.send.shared"
};
AuthenticationResult result = (cca as IByRefreshToken).AcquireTokenByRefreshTokenAsync(scopes, [refresh_token]).Result;
GraphServiceClient client = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new
AuthenticationHeaderValue("Bearer", result.AccessToken);
return Task.FromResult(0);
}));
string id = [message_id];
Message details = client
.Me
.Messages[id]
.Request()
.GetAsync()
.Result; // JUST FOR TESTING, THIS WORKS!
Message reply = client
.Me
.Messages[id]
.CreateReply()
.Request()
.PostAsync().Result; // THIS FAILS!!!
reply.Body.ContentType = BodyType.Html;
reply.Body.Content = [html_code];
client
.Me
.Messages[reply.Id]
.Request()
.UpdateAsync(reply); // HOPE THIS WORKS
client
.Me
.Messages[reply.Id]
.Send()
.Request()
.PostAsync()
.Wait(); // HOPE THIS WORKS TOO
I'm using .NET 4.7.2, Microsoft.Graph 1.17, and Microsoft.Identity.Client v3.0.2-preview (this is because if I try to use any stable one I get an error trying to get the token using only the refresh token)