Exchange日历已删除事件获取及相关技术问题咨询
Let’s break down each of your technical questions with practical, actionable solutions tailored to Exchange Web Services (EWS)—the standard SOAP-based API for interacting with Exchange from Java.
1. How to Retrieve Deleted Events from Exchange Calendar?
There are two reliable approaches to fetch deleted calendar events:
Option 1: Query the Deleted Items Folder
When users perform a "soft delete" (the most common deletion type), calendar events are moved to Exchange’s Deleted Items folder. You can use the FindItem SOAP operation to fetch items from this folder, filtering specifically for appointment-class items (IPM.Appointment).
Option 2: Track Deletions via Sync Operations
For incremental or real-time tracking (including hard deletes that bypass the Deleted Items folder), use the SyncFolderItems operation. This lets you sync changes to the Calendar folder over time, and it returns entries with a ChangeType of Delete for removed items. You’ll need to maintain a SyncState token between requests to keep track of the last synced state.
2. How to Get and Identify Outlook Deleted Items?
When Outlook is connected to an Exchange server, its deleted items directly map to Exchange’s Deleted Items folder. To identify deleted calendar items:
- Check the
ItemClassproperty equalsIPM.Appointment(this distinguishes calendar events from emails, tasks, etc.). - For soft deletes: The item resides in the
Deleted Itemsfolder—you can also check its original parent folder ID if needed. - For hard deletes: These won’t appear in the
Deleted Itemsfolder, so use theSyncFolderItemsoperation (from question 1) to detect them via theDeletechange type.
3. SOAP Requests for the Above Operations
Here are simplified, working SOAP request examples for each key operation:
FindItem (Fetch Deleted Calendar Events from Deleted Items Folder)
<?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:Header> <t:RequestServerVersion Version="Exchange2013" /> </soap:Header> <soap:Body> <FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow"> <ItemShape> <t:BaseShape>IdOnly</t:BaseShape> <t:AdditionalProperties> <t:FieldURI FieldURI="item:Subject" /> <t:FieldURI FieldURI="item:ItemClass" /> </t:AdditionalProperties> </ItemShape> <Restriction> <t:IsEqualTo> <t:FieldURI FieldURI="item:ItemClass" /> <t:FieldURIOrConstant> <t:Constant Value="IPM.Appointment" /> </t:FieldURIOrConstant> </t:IsEqualTo> </Restriction> <ParentFolderIds> <t:DistinguishedFolderId Id="deleteditems" /> </ParentFolderIds> </FindItem> </soap:Body> </soap:Envelope>
SyncFolderItems (Track Deletions from Calendar Folder)
<?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:Header> <t:RequestServerVersion Version="Exchange2013" /> </soap:Header> <soap:Body> <SyncFolderItems xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <FolderId> <t:DistinguishedFolderId Id="calendar" /> </FolderId> <SyncState><!-- Leave empty for initial sync; use returned SyncState for subsequent requests --></SyncState> <ItemShape> <t:BaseShape>IdOnly</t:BaseShape> </ItemShape> <MaxItemsReturned>100</MaxItemsReturned> <SyncScope>NormalItems</SyncScope> </SyncFolderItems> </soap:Body> </soap:Envelope>
In the response, look for ChangeType elements set to Delete—these mark deleted calendar items.
4. Can Exchange Notify Your App When an Appointment is Deleted?
Yes! You can use Exchange Push Notifications (or Pull/Streaming Notifications) to get real-time alerts when calendar items are deleted. Here’s how to set it up:
- Create a Subscription: Send a
SubscribeSOAP request to Exchange, specifying the Calendar folder and includingDeletedin the list of monitored event types. - Handle Notifications: For Push Notifications, Exchange sends an HTTP POST to a publicly accessible URL you provide whenever a deletion occurs. For Pull Notifications, your app periodically polls Exchange for new changes using the
GetEventsoperation. - Process the Alert: The notification payload includes the deleted item’s ID and change type, letting your app react immediately.
Sample Subscribe Request for Push Notifications:
<?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:Header> <t:RequestServerVersion Version="Exchange2013" /> </soap:Header> <soap:Body> <Subscribe xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <PushSubscriptionRequest> <t:FolderIds> <t:DistinguishedFolderId Id="calendar" /> </t:FolderIds> <t:EventTypes> <t:EventType>Deleted</t:EventType> </t:EventTypes> <t:StatusFrequency>1</t:StatusFrequency> <t:URL>https://your-app-url.com/exchange-notifications</t:URL> </PushSubscriptionRequest> </Subscribe> </soap:Body> </soap:Envelope>
Note: Your app’s URL must be accessible from the Exchange server, and you’ll need to handle incoming POST requests with the appropriate SOAP response.
内容的提问来源于stack exchange,提问作者Pasha




