

终止支持通知：2027 年 3 月 31 日， AWS 将终止对亚马逊 WorkMail的支持。2027 年 3 月 31 日之后，您将无法再访问亚马逊 WorkMail 控制台或亚马逊 WorkMail 资源。有关更多信息，请参阅 [Amazon WorkMail 终止支持](https://docs.aws.amazon.com/workmail/latest/adminguide/workmail-end-of-support.html)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用通知
<a name="notifications"></a>

借助 Amazon WorkMail Push Notifications API，您可以接收有关您的邮箱中的更改的推送通知，包括新电子邮件和日历更新。您必须注册 URL（或推送通知响应程序）才能接收通知。借助此功能，开发人员可以为 Amazon WorkMail 用户创建快速响应应用程序，以便快速向应用程序通知用户邮箱中的更改。

有关更多信息，请参阅 [Exchange 中的通知订阅、邮箱事件和 EWS](https://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx)。

您可以订阅特定文件夹（如“收件箱”或“日历”），也可以订阅邮箱更改事件的所有文件夹（包括“新建邮件”、“已创建”和“已修改”）。

可以使用客户端库（如 [EWS Java API](https://github.com/OfficeDev/ews-java-api) 或[托管式 EWS C\$1 API](https://msdn.microsoft.com/en-us/library/office/dn567668(v=exchg.150).aspx)）来访问此功能。[AWS GitHub 页面](https://github.com/aws-samples/amazon-workmail-demo-ews-push-notifications)上提供了使用 AWS Lambda 和 API Gateway（使用 AWS Serverless 框架）开发的完整推送响应程序示例应用程序。它使用 EWS Java API。

下面是一个示例推送订阅请求：

```
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
   <soap:Body>
      <m:Subscribe xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
         <m:PushSubscriptionRequest>
            <t:FolderIds>
               <t:DistinguishedFolderId Id="inbox" />
            </t:FolderIds>
            <t:EventTypes>
               <t:EventType>NewMailEvent</t:EventType>
               <t:EventType>CopiedEvent</t:EventType>
               <t:EventType>CreatedEvent</t:EventType>
               <t:EventType>DeletedEvent</t:EventType>
               <t:EventType>ModifiedEvent</t:EventType>
               <t:EventType>MovedEvent</t:EventType>
            </t:EventTypes>
            <t:StatusFrequency>1</t:StatusFrequency>
            <t:URL>https://YOUR_PUSH_RESPONDER_URL</t:URL>
         </m:PushSubscriptionRequest>
      </m:Subscribe>
   </soap:Body>
</soap:Envelope>
```

下面是成功的订阅请求结果：

```
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <Header xmlns="http://schemas.xmlsoap.org/soap/envelope/">
      <ServerVersionInfo xmlns="http://schemas.microsoft.com/exchange/services/2006/types" MajorVersion="14" MinorVersion="2" MajorBuildNumber="390" Version="Exchange2010_SP2" MinorBuildNumber="3" />
   </Header>
   <soap:Body>
      <m:SubscribeResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
         <m:ResponseMessages>
            <m:SubscribeResponseMessage ResponseClass="Success">
               <m:ResponseCode>NoError</m:ResponseCode>
               <m:SubscriptionId>hKJETtoAdi9PPW0tZDQ4MThmMDoVYB</m:SubscriptionId>
               <m:Watermark>AAAAAAA=</m:Watermark>
            </m:SubscribeResponseMessage>
         </m:ResponseMessages>
      </m:SubscribeResponse>
   </soap:Body>
</soap:Envelope>
```

稍后，通知将发送到在订阅请求中指定的 URL。下面是示例通知：

```
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <t:RequestServerVersion
            xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
            xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" Version="Exchange2010_SP2">
        </t:RequestServerVersion>
    </soap:Header>
    <soap:Body>
        <m:SendNotification
            xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
            xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
            <m:ResponseMessages>
                <m:SendNotificationResponseMessage ResponseClass="Success">
                    <m:ResponseCode>NoError</m:ResponseCode>
                    <m:Notification>
                        <t:SubscriptionId>hKJETtoAdi9PPW0tZDQ4MThmMDoVYB</t:SubscriptionId>
                        <t:PreviousWatermark>ygwAAAAAAAA=</t:PreviousWatermark>
                        <t:MoreEvents>false</t:MoreEvents>
                        <t:ModifiedEvent>
                            <t:Watermark>ywwAAAAAAAA=</t:Watermark>
                            <t:TimeStamp>2018-02-02T15:15:14Z</t:TimeStamp>
                            <t:FolderId Id="AAB2L089bS1kNDgxOGYwOGE5OTQ0="></t:FolderId>
                            <t:ParentFolderId Id="AAB2L089bS1kNDgxOGYwOGE="></t:ParentFolderId>
                        </t:ModifiedEvent>
                    </m:Notification>
                </m:SendNotificationResponseMessage>
            </m:ResponseMessages>
        </m:SendNotification>
    </soap:Body>
</soap:Envelope>
```

要确认推送通知响应程序已收到通知，它必须回复以下信息：

```
<?xml version="1.0"?>
  <s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
      <SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
        <SubscriptionStatus>OK</SubscriptionStatus>
      </SendNotificationResult>
    </s:Body>
  </s:Envelope>
```

要取消订阅接收推送通知，客户必须在 `SubscriptionStatus` 字段中发送取消订阅响应，类似于下面这样：

```
<?xml version="1.0"?>
  <s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
      <SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
        <SubscriptionStatus>Unsubscribe</SubscriptionStatus>
      </SendNotificationResult>
    </s:Body>
  </s:Envelope>
```

为验证您的推送通知响应程序的运行状况，Amazon WorkMail 会发送一个“检测信号”（也称为 `StatusEvent`）。发送的频率将由在初始订阅请求中提供的 `StatusFrequency` 参数确定。例如，如果 `StatusFrequency` 等于 **1**，则每分钟发送一个 `StatusEvent`。此值可以介于 1 到 1440 分钟之间。此 `StatusEvent` 类似于下面这样：

```
<?xml version="1.0 (http://www.w3.org/TR/REC-xml/)" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
    <t:RequestServerVersion xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" Version="Exchange2010_SP2"/>
</soap:Header>
<soap:Body>
    <m:SendNotification xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
    <m:ResponseMessages>
        <m:SendNotificationResponseMessage ResponseClass="Success">
            <m:ResponseCode>NoError</m:ResponseCode>
            <m:Notification>
                <t:SubscriptionId>hKJETtoAdi9PPW0tZDQ4MThmMDoVYB</t:SubscriptionId>
                <t:PreviousWatermark>AAAAAAAAAAA=</t:PreviousWatermark>
                <t:MoreEvents>false</t:MoreEvents>
                <t:StatusEvent>
                    <t:Watermark>AAAAAAAAAAA=</t:Watermark>
                </t:StatusEvent>
            </m:Notification>
        </m:SendNotificationResponseMessage>
    </m:ResponseMessages>
</m:SendNotification>
</soap:Body>
</soap:Envelope>
```

如果客户端推送通知响应程序未能以与以前相同的 `OK` 状态进行响应，则最多在 `StatusFrequency` 分钟内重试通知。例如，如果 `StatusFrequency` 等于 5，且第一个通知失败，则它最多在 5 分钟内重试，并且在每次重试之间使用指数回退。如果在重试时间到期后未发送通知，则订阅将失效，并且不会发送任何新通知。您必须创建新订阅以继续接收有关邮箱事件的通知。目前，每个邮箱最多可以有 3 个订阅。