Please note that since Graph API v. 5.0 (march 2023), Microsoft introduced an annoying breaking change, not really well documented (besides obscurely here).
Now, SendMail cannot be used anymore as a method of a User. You will get a CS1955 Non-invocable member cannot be used like a method compiler error if you try to do that.
You will have to do something like this:
// Your old Message object definition
Microsoft.Graph.Models.Message msg = new()
{
From = ...,
ToRecipients = ...,
Subject = "...",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "..."
}
};
Microsoft.Graph.Users.Item.SendMail.SendMailPostRequestBody body = new()
{
Message = msg,
SaveToSentItems = false // or true, as you want
};
try
{
await graphClient.Users["your user GUID"]
.SendMail
.PostAsync(body);
}
catch (Exception ex)
{
// log your exception here
}