使用通知 - Amazon WorkMail

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用通知

使用 Amazon WorkMail 推送通知 API,您可以接收有關信箱變更的推播通知,包括新的電子郵件和行事曆更新。您必須註冊 URL(或推送通知回應者)才能接收通知。使用此功能,開發人員可以為 Amazon 使 WorkMail 用者建立回應式應用程式,因為應用程式會快速收到使用者信箱變更的通知。

如需詳細資訊,請參閱通知訂閱、信箱事件,以及在 Exchange 的 EWS

您可以訂閱特定資料夾 (例如 [收件匣] 或 [行事曆]),或訂閱信箱變更事件的所有資料夾 (包括 [新增郵件]、[已建立] 及 [已修改])。

您可以使用用戶端程式庫,例如 EWS Java API受管理的 EWS C# API 來存取此功能。此頁面提供使用 AWS Lambda 和 API Gateway (使用 AWS 無伺服器架構) 開發的推播回應程式的完整範例應用程式AWS GitHub 。它使用 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 會傳送「心跳訊號」(也稱為 aStatusEvent)。傳送的頻率取決於在初始訂閱請求所提供的 StatusFrequency 參數。例如,如果StatusFrequency等於1StatusEvent則每 1 分鐘傳送一次。這個值的範圍介於 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>

如果用戶端推播通知回應程式無法以與之前相同的OKStatusFrequency狀態回應,則會重試通知最多幾分鐘。例如,如果 StatusFrequency 等於 5 且第一個通知失敗,它會重試最多 5 分鐘且在每個重試中以指數退避。如果在重試時間過期後仍未傳遞通知,則訂閱會失效,且不會傳遞新的通知。您必須建立新的訂閱以持續收到信箱事件的通知。目前,每個信箱最多可以訂閱三個訂閱。