Search code examples
node.jsoutlook-web-addins

How to create a category and apply it to an email


Is it possible create a category in outlook programmatically?

I set up a hello world outlook-addin by following MS's tutorials. And I see how I have access to all the different properties of a particular email. However, I'm stumped about how to work with categories.


Solution

  • I had to pass in the following SOAP request through Office.context.mailbox.makeEwsRequestAsync() to create a category called "Muktader" and apply it to an email identified by the item id.

    <?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_SP1" />
      </soap:Header>
      <soap:Body>
        <m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">
          <m:ItemChanges>
            <t:ItemChange>
              <t:ItemId Id="AAMkAGVlOTZjNTM3LWVjNjgtNGZlNi04MTBkLWIyNjNjNWEyY2VlNABGAAAAAABpsgv3HB+wQJRg4K+r7AmBBwBJi9ckXu/REb74AIBfn0G8AAAUrOs1AACN8cPrPdSYR5RdhR69ULJ0AAACOkAqAAA=" ChangeKey="CQAAABYAAACN8cPrPdSYR5RdhR69ULJ0AAACR0YO" />
              <t:Updates>
                <t:SetItemField>
                  <t:FieldURI FieldURI="item:Categories" />
                  <t:Message>
                    <t:Categories>
                      <t:String>Muktader</t:String>
                    </t:Categories>
                  </t:Message>
                </t:SetItemField>
              </t:Updates>
            </t:ItemChange>
          </m:ItemChanges>
        </m:UpdateItem>
      </soap:Body>
    </soap:Envelope>