

サポート終了通知: 2027 年 3 月 31 日、 AWS は Amazon WorkMail のサポートを終了します。2027 年 3 月 31 日以降、Amazon WorkMail コンソールまたは Amazon WorkMail リソースにアクセスできなくなります。詳細については、[Amazon WorkMail のサポート終了](https://docs.aws.amazon.com/workmail/latest/adminguide/workmail-end-of-support.html)」を参照してください。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

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

Amazon WorkMail プッシュ通知 API を使用すると、新しい E メールやカレンダーの更新など、メールボックスでの変更に関するプッシュ通知を受信できます。通知を受け取るには、URL (またはプッシュ通知のレスポンダ) を登録する必要があります。この機能を使用すると、アプリケーションはユーザーのメールボックスから変更に関する通知をすぐに受け取るため、開発者は Amazon WorkMail のユーザー向けの応答性に優れたアプリケーションを作成できます。

詳細については、[Exchange の通知サブスクリプション、メールボックスイベント、および EWS](https://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx) を参照してください。

メールボックスの変更イベント (NewMail、作成済み、変更済みを含む) について、受信トレイやカレンダーなど特定のフォルダ、またはすべてのフォルダをサブスクライブできます。

[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 Lambda および API Gateway を使用 (AWS Serverless フレームワークを使用) して開発された、プッシュレスポンダの完全なサンプルアプリケーションは、[AWS GitHub ページから入手できます](https://github.com/aws-samples/amazon-workmail-demo-ews-push-notifications)。これには 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** に等しい場合、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 つのサブスクリプションにサブスクライブできます。