none
Outlook Addin and EWS GetAttachment RRS feed

  • Question

  • So I'm roughly following the GetAttachment Example from Microsoft -- http://docs.microsoft.com/en-us/outlook/add-ins/get-attachments-of-an-outlook-item

    But, my WebService that receives the EWS Token, EWS URL, and Attachment ID is written in Python.  My problem seems to be to a permission error.  When I try to retrieve the Attachment by ID using an EWS Soap request, I an ErrorItemNotFound response.

    Here is what I have working.

    I have an Outlook AddIn written in Javascript that responds to mail item selections.  

    I retrieve an EWS Token using the isRest=false option: 

    Office.context.mailbox.getCallbackTokenAsync(getEWSCallback, options);


    For mail that has an attachment, I extract information about the attachment including the attachment Id. 

    Here is a sample of the attachment information:

    {
    "id": "XZkADdlMDAxOTFiLWZmMWYtNGI1Ni1iYmM2LTlhOTJjYTBmMTI1MQBGAAAAAAAO1b910PexQpLkqgde51DABwAyR2+p4hG4RbXOV7pJuYtiAAAAAAEMAAAyR2+p4hG4RbXOV7pJuYtiAABsXaGoAAABEgAQAJ8Lans/ZeZLrkpk6mQ/QQg=",
    "name": "xxxxxxxxxxx.docx",
    "contentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "size": 162008,
    "attachmentType": 0,
    "isInline": false
    }

    I pass the EWS Token, EWS Url, and Attachment information to my webservice; which is written in Python.  

    My WebService constructs the soap request:

    <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000} span.s1 {font-variant-ligatures: no-common-ligatures} </style>

    <?xml version="1.0" encoding="utf-8"?>

    <soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"

    xmlns:xsd="https://www.w3.org/2001/XMLSchema"

    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">

    <soap:Header>

    <t:RequestServerVersion Version="Exchange2013" />

    </soap:Header>

      <soap:Body>

        <GetAttachment xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"

        xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">

          <AttachmentShape/>

          <AttachmentIds>

            <t:AttachmentId Id="XZkADdlMDAxOTFiLWZmMWYtNGI1Ni1iYmM2LTlhOTJjYTBmMTI1MQBGAAAAAAAO1b910PexQpLkqgde51DABwAyR2+p4hG4RbXOV7pJuYtiAAAAAAEMAAAyR2+p4hG4RbXOV7pJuYtiAABsXaGoAAABEgAQAJ8Lans/ZeZLrkpk6mQ/QQg="/>

          </AttachmentIds>

        </GetAttachment>

      </soap:Body>

    </soap:Envelope>

    I then send a Webrequest with python:

    authHeaders = {
    'Authorization': "Bearer " + ewsToken,
    'Content-type': 'text/xml; charset=utf-8'
    }
    webResp = requests.post(url=ewsUrl, headers=authHeaders, data=requestString)

    The response I get is below:

    <?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="2430" MinorBuildNumber="27" 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:GetAttachmentResponse 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:GetAttachmentResponseMessage ResponseClass="Error">
    <m:MessageText>The specified object was not found in the store., The process failed to get the correct properties.</m:MessageText>
    <m:ResponseCode>ErrorItemNotFound</m:ResponseCode>
    <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
    <m:Attachments/>
    </m:GetAttachmentResponseMessage>
    </m:ResponseMessages>
    </m:GetAttachmentResponse>
    </s:Body>
    </s:Envelope>

    My understanding is that the ErrorItemNotFound response indicates either (1) The item doesn't exists or (2) I don't have permission to access it.

    If I use a corrupt EWS Token, I get a Http 401 error that indicates I'm not authorized to make the EWS Post.  So I believe the Bearer authentication is working correctly.

    Any thoughts or help?

    Thank you,

    Jon

    Monday, November 11, 2019 7:27 PM