Search code examples
outlookoffice-jsexchangewebservicesoutlook-web-addins

return a Count of emails inside Trash folder


How i can get the count of emails inside Trash folder with outlook web add-ins i try to use EWS xml, but it show an error

let xml =
    '<?xml version="1.0" encoding="utf-8"?>\n' +
    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">\n' +
    '  <soap:Header>\n' +
    '    <t:RequestServerVersion Version="Exchange2007_SP1" />\n' +
    '  </soap:Header>\n' +
    '  <soap:Body>\n' +
    '    <m:GetFolder>\n' +
    '      <m:FolderShape>\n' +
    '        <t:BaseShape>IdOnly</t:BaseShape>\n' +
    '      </m:FolderShape>\n' +
    '      <m:FolderIds>\n' +
    '        <t:DistinguishedFolderId Id="inbox" />\n' +
    '      </m:FolderIds>\n' +
    '    </m:GetFolder>\n' +
    '  </soap:Body>\n' +
    '</soap:Envelope>';


var mailbox = Office.context.mailbox;
mailbox.makeEwsRequestAsync(xml, function(result) {
  console.log(result);
  //var response = $.parseXML(result.value);
  //var extendedProps = response.getElementsByTagName("ExtendedProperty")
});

result :

message: "The remote server returned an error: (500) Internal Server Error."

Solution

  • Request PR_CONTENT_COUNT MAPI property:

    <FolderShape>
      <t:BaseShape>IdOnly</t:BaseShape>
      <t:AdditionalProperties>
        <t:ExtendedFieldURI PropertyType="Integer" PropertyTag="0x3602"/>
      </t:AdditionalProperties>
    </FolderShape>
    

    Or you can request TotalCount property:

    <t:AdditionalProperties>
      <t:FieldURI FieldURI="folder:TotalCount"/>
    </t:AdditionalProperties>
    

    Update: I could not execute your request above (same error), but the following works just fine from "EWS Request Pad" in OutlookSpy (I am its author):

    <?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="Exchange2007_SP1"/>
      </soap:Header>
      <soap:Body>
        <GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
                   xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
          <FolderShape>
            <t:BaseShape>IdOnly</t:BaseShape>
            <t:AdditionalProperties>
              <t:ExtendedFieldURI PropertyType="Integer" PropertyTag="0x3602"/>
            </t:AdditionalProperties>
          </FolderShape>
          <FolderIds>
            <t:DistinguishedFolderId Id="deleteditems"/>
          </FolderIds>
        </GetFolder>
      </soap:Body>
    </soap:Envelope>