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

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>' +
        '</soap:Envelope>';

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.  

March 10th, 2015 5:48pm

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.
Free Windows Admin Tool Kit Click here and download it now
March 16th, 2015 9:04am

You would need to change the Target folder to reflect the Mailbox you wanted to copy/move to

          <t:DistinguishedFolderId Id="junkemail">
            <t:Mailbox>
              <t:EmailAddress>user@domain.com</t:EmailAddress>
            </t:Mailbox>
          </t:DistinguishedFolderId>

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.

Cheers
Glen

March 16th, 2015 11:17pm

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)
            {
                item.Load();
                ItemId ItemToMoveId = new ItemId(item.Id.UniqueId.ToString());
                Item ItemToMove = Item.Bind(service, ItemToMoveId);
                ItemToMove.Move(SpamFolder.Id);
                //item.Move(SpamFolder.Id);

            }

Free Windows Admin Tool Kit Click here and download it now
March 19th, 2015 9:22am

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

Cheers
Glen

March 20th, 2015 2:17am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics