本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用通知
借助 Amazon WorkMail 推送通知 API,您可以接收有关邮箱变更的推送通知,包括新的电子邮件和日历更新。您必须注册 URL(或推送通知响应程序)才能接收通知。借助此功能,开发人员可以为 Amazon WorkMail 用户创建响应式应用程序,因为应用程序会从用户邮箱中快速收到有关更改的通知。
有关更多信息,请参阅 Exchange 中的通知订阅、邮箱事件和 EWS
您可以订阅特定文件夹(如“收件箱”或“日历”),也可以订阅邮箱更改事件的所有文件夹(包括“新建邮件”、“已创建”和“已修改”)。
可以使用客户端库(如 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
等于 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 个订阅。