EWS Managed API - How to copy items from one mailbox to other
-
Monday, December 03, 2012 8:34 PM
Hi,
I am writing an application to sync contacts,appointments,tasks etc from one mailbox to other. I am able to retrieve changes to these items using SyncFolderItems but could not find a way to copy the changes to a different mailbox. It looks like I have to create a new item for each of these types on the destination mailbox. If that is the case how do I get all the properties on the source item onto the new item on the destination.
All Replies
-
Tuesday, December 04, 2012 5:59 AM
If you have Exchange 2010 or 2013 there are 2 ways you can copy an Item and not lose any fidelity (properties) the first is
The CopyItem Operation
http://msdn.microsoft.com/en-us/library/exchange/aa565012%28v=exchg.140%29.aspx and http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.copyitems%28v=exchg.80%29.aspx
If you have two Exchange servers in two different Exchange Orgnizations or even within your Exchange Org if CopyItem doesn't work for you. Then you can use the ExportItem and UploadItem operations http://msdn.microsoft.com/en-us/library/exchange/hh135142%28v=exchg.140%29.aspx
Cheers
Glen -
Tuesday, December 04, 2012 4:16 PM
Thanks for your reply Glen.
Is there a way I could achieve the same functionality on exchange 2007 sp1 also. I tried the first option in 2007 but it fails.
I want to use the common code across different exchange versions.
Regards,
vamshee
-
Wednesday, December 05, 2012 5:50 AM
No Export/Upload Items was a feature introduced in 2010 SP1, are you running Service Pack 3 for 2007 I know there where some changes to help Cross Mailbox copies in later service packs on 2007 but I think this operation gets affected depending on where your Stores are placed. Eg stores in the same Mailbox Database should be okay etc.
Cheers
Glen -
Wednesday, December 05, 2012 3:28 PM
We are on 2007 sp1 i believe but mailboxes could be across different DBs. I am fine with creating a new item on the destination mailbox and assigning all the properties of the source item. Is this the only option I have and if yes what all properties i need to assign to the item in destination.
-
Thursday, December 06, 2012 2:57 AM
There is no way in EWS to select all properties so you will need to define every property you want to get/set, Contacts are easy but appointments and tasks are a lot harder especially if you have recurrences etc. You'll need to use a Mapi editor like outlookspy or MFCMapi to see what all the Mapi properties are.
One option you may want to try is copy the item to a public folder as an intermediary which might work for you.
Cheers
Glen -
Thursday, December 06, 2012 1:48 PM
Thanks a lot for your input Glen!!
I will keep you posted on the route I take.
-
Thursday, December 13, 2012 2:08 PMGlen,
I am trying to access message ID (PR_INTERNET_MESSAGE_ID) from task items and could not find a way to retrieve this property from my source item.I am access message properties using
BindToItems(ItemIDList, new PropertySet(BasePropertySet.FirstClassProperties)
I tried adding additional properties to the PropertySet(shown below) but did not get the messageID.
ExtendedPropertyDefinition ExProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, "PR_INTERNET_MESSAGE_ID", MapiPropertyType.String);
BindToItems(ItemIDList, new PropertySet(BasePropertySet.FirstClassProperties, ExProp)); -
Friday, December 14, 2012 8:33 AM
Task Items don't get sent (eg they don't transit the Transport Pipeline in Exchange) so they don't get assigned an Internet Message Id (which is assigned by the MTA). Normal Appointments, Contacts and a number of other Items are all similar.
Cheers
Glen -
Wednesday, December 19, 2012 10:33 PM
Hi Glen,
I am doing Item.Copy operation to copy an item from source mailbox to destination. I want to add few custom headers on the item in destination folder. Is there a way i could get a handle to the copied item from destination folder. I am copying items across mailboxes so copy operation doesn't return a handle to the item in the destination. I tried FindItems but I am unable to provide a unique search criteria to return just the copied item.
-
Thursday, December 20, 2012 11:31 AM
see http://msdn.microsoft.com/en-us/library/exchange/aa565012%28v=exchg.80%29.aspx " Starting with Exchange 2007 SP1 with Update Rollup 4 (RU4) applied, the item identifier of the new item is returned in the response message. Item identifiers are not returned in responses for cross-mailbox or mailbox to public folder CopyItem operations.
Cheers
Glen -
Thursday, December 20, 2012 3:45 PMI am doing a cross mailbox copy operation.
-
Friday, December 21, 2012 12:43 AM
You might want to try the PidTagSearchKey property which in theory should not change after a folder copy http://msdn.microsoft.com/en-us/library/office/cc815908.aspx. Otherwise create your own custom property to track it.
Cheers
Glen

