首页 > 解决方案 > Microsoft Graph SendMail 返回 ErrorInternalServerError

问题描述

我正在编写一个程序,使用官方的 Microsoft Graph 包在 VB.Net 中发送内部电子邮件。起初我用它来发送日历邀请,几个月来效果很好,但是当我尝试添加发送电子邮件的功能时,我不断收到内部服务器错误。

从其他时间来看,人们从 Graph 收到此错误,这似乎是在发送格式错误的请求或给出不太有意义的值时。我正在使用包中的构造函数,并使用与在线每个示例基本相同的构造方法,因此请求的结构不会出错,并且我使用的唯一字段只是接受文本而不做任何东西,所以我认为这也不是问题。

我在 Azure 中拥有正确的权限:Azure 中权限的屏幕截图,包括 Mail.Send

这是我构建电子邮件的代码:

Function DefineImportantEmail(Locations As String, Recipients As List(Of (String, String))) As Message
    Dim title = "IMPORTANT OUTAGE NOTIFICATION"
    Dim message = "Outage at " & Locations

    Dim RecipientList = New List(Of Recipient)
    For Each recipient In Recipients
        RecipientList.Add(New Attendee With {
                .EmailAddress = New EmailAddress With {
                    .Address = recipient.Item1,
                    .Name = recipient.Item2
                },
                .Type = AttendeeType.Optional
            })
    Next

    Return New Message With {
        .Subject = title,
        .Body = New ItemBody With {
            .ContentType = BodyType.Text,
            .Content = message
        },
        .ToRecipients = RecipientList
    }
End Function

这是我用来发送电子邮件的代码:

Sub SendImportantEmail(Locations As String, Recipients As List(Of (String, String)))
    Dim SaveToSentItems = True
    Dim graphClient = GetGraphClient()
    Dim EventObject = DefineImportantEmail(Locations, Recipients)
    Dim request = graphClient.Users("xxxxx@xxxxxxxxxxxxxxx.com").SendMail(EventObject, SaveToSentItems).Request().PostAsync()
    request.Wait()
End Sub

GetGraphClient 函数适用于我尝试过的任何其他 API 端点,所以我没有包含它。被审查的用户来自我们的组织,也是我在该程序的第一个版本中发送日历邀请的用户。

这是我收到的完整错误消息:

(代码:ErrorInternalServerError 消息:发生内部服务器错误。操作失败。ClientRequestId:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx )---> 状态代码:InternalServerError Microsoft.Graph.ServiceException:代码:ErrorInternalServerError 消息:内部服务器发生了错误。操作失败。ClientRequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

标签: vb.netmicrosoft-graph-api

解决方案


推荐阅读