如何使用 EWS Managed API 2.2 创建类别并将其关联到联系人

How to Create and Associate a Category to a Contact using EWS Managed API 2.2

是否可以使用 EWS Managed API 创建类别项目对象并将其与联系人相关联?

您可以使用类别 属性 https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.item.categories(v=exchg.80).aspx 将类别分配给邮箱中的任何对象。

要在 Outlook 或 OWA 中显示特定的 color/description,您传入的类别必须与主类别列表中的项目相匹配。您可以使用 EWS read/modify 邮箱中的主类别列表,例如 https://social.msdn.microsoft.com/Forums/en-US/e5c5f072-0b5c-49ce-9db7-57f76f5e011e/edit-master-category-list-in-exchange-2010-via-ews?forum=exchangesvrdevelopment and https://social.msdn.microsoft.com/Forums/en-US/a3917500-2bbc-4def-98b4-696e49efed6f/adding-categories-to-a-users-master-category-list-in-exchange-2010-using-ews?forum=exchangesvrdevelopment

我在寻找使用 EWS 而非托管 API 更新主类别列表时遇到了这个 post。如果其他人想要做同样的事情,这是我想出的解决方案,它使用 Python 和请求:

import base64
import requests
from requests_ntlm import HttpNtlmAuth


# Create the XML request template for EWS
payload = r"""<?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:UpdateUserConfiguration>
      <t:UserConfigurationName Name="CategoryList">
        <t:DistinguishedFolderId Id="calendar">
        <t:Mailbox>
        <t:EmailAddress>your_email@your_domain.com</t:EmailAddress>
        <t:RoutingType>SMTP</t:RoutingType>
        <t:MailboxType>Mailbox</t:MailboxType>
        </t:Mailbox>
        </t:DistinguishedFolderId>
      </t:UserConfigurationName>
      <t:XmlData>{}</t:XmlData>
    </m:UpdateUserConfiguration>
  </soap:Body>
</soap:Envelope>"""

# Create the categories XML
# Colors: https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxocfg/eb7cac90-6200-4ac3-8f3c-6c808c681c8b
xml_data = r"""<?xml version="1.0"?>
  <categories default="First category" xmlns="CategoryList.xsd">
  <category name="First category" color="1" />
  <category name="Second category" color="2" />
  </categories>"""

# Encode the payload and insert it into the XML request
xml = base64.b64encode(xml_data.encode())
payload = payload.replace('{}', str(xml).strip('b\''))

# Use requests with the NTLM authentication libary to submit the request
headers = {'content-type': 'text/xml'}
ews_url = 'https://mail.your-organizations-exchange-server.com/EWS/Exchange.asmx'
session = requests.Session()
session.auth = HttpNtlmAuth(exhange_username, exchange_password)
response = session.post(ews_url, data=payload, headers=headers)
print(response.text)