首页 > 解决方案 > 使用 O365 Graph Api 创建事件时显示日历请求

问题描述

我正在使用 Microsoft.Graph v4.9.0 nuget 包在用户日历中生成事件。该事件已成功创建并在目标用户的日历中可见,但收件箱中没有通知他已创建新事件。

目标是获得新事件的邀请,他可以接受/拒绝/标记为暂定..

调用api的代码很简单:

var newEvent = new Event() {}; //omitted, see the serialized value below

var graphResult =
    await _graphServiceClient
          .Users[userId]
          .Calendar
          .Events
          .Request()
          .AddAsync(newEvent);

这是 newEvent 的样子:

{
    "AllowNewTimeProposals": false,
    "Attendees": [{
            "Type": "Required",
            "EmailAddress": {
                "Address": "internal_user@mycompany.com",
                "Name": "internal user",
                "ODataType": "microsoft.graph.emailAddress"
            },
            "ODataType": "microsoft.graph.attendee"
        }, {
            "Type": "Required",
            "EmailAddress": {
                "Address": "external_user@notmycompany.com",
                "Name": "external user",
                "ODataType": "microsoft.graph.emailAddress"
            },
            "ODataType": "microsoft.graph.attendee"
        }
    ],
    "Body": {
        "Content": "<html>Test event</html>",
        "ContentType": "Html",
        "ODataType": "microsoft.graph.itemBody"
    },
    "End": {
        "DateTime": "2021-11-09T11:00:00.0000000",
        "TimeZone": "Central Europe Standard Time",
        "ODataType": "microsoft.graph.dateTimeTimeZone"
    },
    "HasAttachments": false,
    "Importance": "Normal",
    "IsOnlineMeeting": false,
    "IsOrganizer": false,
    "IsReminderOn": false,
    "Location": {
        "DisplayName": "",
        "ODataType": "microsoft.graph.location"
    },
    "Organizer": {
        "EmailAddress": {
            "Address": "external_user@notmycompany.com",
            "Name": "external user",
            "ODataType": "microsoft.graph.emailAddress"
        },
        "ODataType": "microsoft.graph.recipient"
    },
    "ReminderMinutesBeforeStart": 0,
    "ResponseRequested": true,
    "ShowAs": "Tentative",
    "Start": {
        "DateTime": "2021-11-09T10:00:00.0000000",
        "TimeZone": "Central Europe Standard Time",
        "ODataType": "microsoft.graph.dateTimeTimeZone"
    },
    "Subject": "Test event",
    "Type": "SingleInstance",
    "ODataType": "microsoft.graph.event"
}

活动的组织者是不属于公司的用户,因此他有一个外部电子邮件地址(例如来自 gmail)。正如我在这里读到的那样,如果组织者与我们正在为以下内容创建条目相同,则可能会出现问题:相关的stackoverflow问题

内部用户是我们正在使用的图形 api 公司的成员。(该事件是在他的日历中生成的)

他们都作为与会者添加到活动中。

然后奇怪的是,如果我将 Outlook 中日历中的事件保存为 .ics 文件,则组织者不是外部用户,而是内部用户。

ATTENDEE;CN="External user";RSVP=TRUE:external_user@notmycompany.com
ORGANIZER;CN="Internal user":mailto:internal_user@mycompany.com

我有点不知道现在要尝试在收件箱中为内部用户提供日历通知。

标签: c#.netmicrosoft-graph-apioffice365

解决方案


推荐阅读