How to move an email from user mailbox to shared mailbox using apps for office mail app RRS feed

  • Question

  • How can I move an email from a users main mailbox to a shared mailbox using apps for office.  I know I can do this manually but i am creating an for owa/outlook that would be a button to move the item.  I have tried using ews but can only find the commands to move emails inside the users mailbox

    for example : 

    '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
            '               xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
            '               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"' +
            '               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '  <soap:Header>' +
            '    <t:RequestServerVersion Version="Exchange2013" />' +
            '  </soap:Header>' +
            '  <soap:Body>' +
            '    <m:MoveItem>' +
            '      <m:ToFolderId>' +
            '        <t:DistinguishedFolderId Id="junkemail" />' +
            '      </m:ToFolderId>' +
            '      <m:ItemIds>' +
            '        <t:ItemId Id="' + id + '" ' +
            '                  ChangeKey="' + changeKey + '" />' +
            '      </m:ItemIds>' +
            '    </m:MoveItem>' +
            '  </soap:Body>' +

    Can I create a xml that would would do this?  Is there a way to do it using the EWS service reference.  I do not want to use import/export to do this.  

    Tuesday, March 10, 2015 5:48 PM

All replies

  • Hi ExploringDotNet,

    Thanks for posting in MSDN forum.

    As far as I know, the apps for Office doesn't provide the API to achieve.

    However I think it maybe possible to achieve through the EWS, so I would move it to Exchange Development forum to see whether there is an solution.

    Thanks for your understanding.

    Regards & Fei

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 12, 2015 9:22 AM
  • While doing the move is possible using EWS (eg the MoveItem operation should work as long as you have rights to both mailboxes), however the auth token that you get in an a Mail App will only allow you to access the current mailbox. So this token won't allow you to copy the Item into the shared mailbox, (You could forward it to the shared Mailbox). In Outlook you can still use an older VSTO plugin to do this with the Outlook OOM.


    Sunday, March 15, 2015 11:44 PM
  • I want to use moveitem only.  However I can not figure out how to move it to the shared mailbox. The code above works for moving items inside of the same mailbox but how do I move it to the shared mailbox/inbox? What would i have to change?  I can not seem to find an example of this anywhere.
    Monday, March 16, 2015 1:03 PM
  • You would need to change the Target folder to reflect the Mailbox you wanted to copy/move to

              <t:DistinguishedFolderId Id="junkemail">

    However as I said in a MailApp the auth token your using won't allow you to access a Mailbox other then your own (including Shared Mailboxes,  room Mailboxes etc). So if you try to use this I would expect you will see an error detailing this.


    Tuesday, March 17, 2015 3:16 AM
  • yes I was able to make it work using Microsoft.Exchange.WebServices.Data and writing it as a web API,  however i am unable to to authenticate the user if it is hosted on another server (without them retyping their password.  I assume that their is a matching java script version of what i am doing on the api side.  I am just stuck trying to figure it out.  the below code works as a Web Api if i could authenticate the user.    

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
                service.Url = new Uri("Ews url");
                service.Credentials = CredentialCache.DefaultCredentials;
                //service.UseDefaultCredentials = true;

                // Create a new folder view, and pass in the maximum number of folders to return.
                FolderView view = new FolderView(5);
                // Create an extended property definition for the PR_REPLICA_LIST property.
                ExtendedPropertyDefinition PR_REPLICA_LIST = new ExtendedPropertyDefinition(0x6698, MapiPropertyType.Binary);

                view.PropertySet = new PropertySet(BasePropertySet.IdOnly, FolderSchema.DisplayName, PR_REPLICA_LIST);

                // get to the inbox folder of spam mailbox
                Mailbox SpamMailbox = new Mailbox("Smtp of other mailbox");
                FolderId SpamInbox = new FolderId(WellKnownFolderName.Inbox, SpamMailbox);

                Folder SpamFolder = Folder.Bind(service, SpamInbox);

                FindItemsResults<Item> findItems = service.FindItems(WellKnownFolderName.JunkEmail, new ItemView(10));
                foreach (Item item in findItems)
                    ItemId ItemToMoveId = new ItemId(item.Id.UniqueId.ToString());
                    Item ItemToMove = Item.Bind(service, ItemToMoveId);


    Thursday, March 19, 2015 1:21 PM
  • So where are you running this code ? is this a aspx or web app ?

    If your impersonating the user in ASPX you can start to have Kerberos  delegation issues if you try and access another server I would have a look at http://blogs.msdn.com/b/emeamsgdev/archive/2012/11/05/exchange-web-services-from-a-web-application-using-windows-authentication.aspx


    Friday, March 20, 2015 6:16 AM