Warm tip: This article is reproduced from serverfault.com, please click

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

(c# - how to handle throttling with MSGraphClient while sending email)

发布于 2021-01-27 15:55:46

我正在使用以下代码使用 microsoft graph 发送电子邮件

等待 graphClient.Me.SendMail(message, true).Request().PostAsync()

由于后期操作不返回任何内容,那么如何检测状态代码 429(油门响应代码)并处理它。

Questioner
riks
Viewed
0
Dev 2021-01-29 21:02:30

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

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