如何在Outlook的Deleted Items文件夹中创建EWS项目(日历事件或联系人)?

时间:2019-05-28 10:17:31

标签: outlook office365 exchangewebservices

我试图将项目重新创建到Deleted Items文件夹中,但是什么也没有发生,我得到了以下错误“ ErrorCannotCreateCalendarItemInNonCalendarFolder”或“ ErrorCannotCreateContactInNonContactFolder”。如何克服这个问题?

我使用该请求对正文进行了 POST

    "<?xml version=\"1.0\" encoding=\"utf-8\"?> "
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
                   "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" >"
      "<soap:Header> "
        "<t:RequestServerVersion Version=\"Exchange2013\" /> "
        "<t:ExchangeImpersonation> "
          "<t:ConnectingSID> "
            "<t:PrincipalName>%MAIL_BOX%</t:PrincipalName> "     // <<------- MAIL_BOX ---- FILLED IN BY A TEMPLATE PARAM
          "</t:ConnectingSID> "
        "</t:ExchangeImpersonation> "
      "</soap:Header> "
      "<soap:Body> "
        "<CreateItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" "
                    "MessageDisposition=\"SaveOnly\" "
                    "SendMeetingInvitations=\"SendToNone\"> "
          "<SavedItemFolderId>"
            "<t:FolderId Id=\"%FOLDER_ID%\"/>"                             // <<------- FOLDER_ID ---- FILLED IN BY A TEMPLATE PARAM
          "</SavedItemFolderId>"
          "<Items>"
            "%ITEMS_CONTENT%"                                              // <<------- ITEMS_CONTENT ---- FILLED IN BY A TEMPLATE PARAM
          "</Items>"
        "</CreateItem>"
      "</soap:Body>"
    "</soap:Envelope>";

得到这样的回应:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1922" MinorBuildNumber="23" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
    </s:Header>
    <s:Body>
        <m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <m:ResponseMessages>
                <m:CreateItemResponseMessage ResponseClass="Error">
                    <m:MessageText>Cannot create a calendar item in a non-calendar folder.</m:MessageText>
                    <m:ResponseCode>ErrorCannotCreateCalendarItemInNonCalendarFolder</m:ResponseCode>
                    <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
                    <m:Items />
                </m:CreateItemResponseMessage>
            </m:ResponseMessages>
        </m:CreateItemResponse>
    </s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:2)

因为“已删除邮件”文件夹类为IPF。请注意EWS限制您在这些类型的文件夹中创建“日历”或“联系人”项目,因此会收到错误消息。一种解决方法是,在普通的Calendar或Contacts文件夹中创建Items,然后在创建后使用Move操作将其移动。