如何在发送电子邮件时使用 MSGraphClient 处理节流

how to handle throttling with MSGraphClient while sending email

我正在使用以下代码使用 Microsoft Graph 发送电子邮件

等待graphClient.Me.SendMail(消息,真).Request().PostAsync()

既然post操作没有return任何东西那么如何检测状态代码429(油门响应代码)并处理它。

PostAsync() 方法应该在出错时抛出 ServiceException。例如:

try
{
     await graphClient.Users[userId].SendMail(message).Request().PostAsync();
} 
catch (Microsoft.Graph.ServiceException e)
{
     Console.WriteLine(e.Error);
}