none
Downloading Attachment Using Exchange Web Service RRS feed

  • Question

  • I want to download/ access attachment from particular mailbox. I am trying to do using following code however I am not getting any attachment. (may be because AttachmentID's are not proper)

     

      ExchangeServiceBinding esb = new ExchangeServiceBinding();
     esb.RequestServerVersionValue = new RequestServerVersion();
    esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
    esb.Credentials = new NetworkCredential("<USER_ID>", "<Password>", "<Domain>");
    esb.Url = @"https://<Server_FQDN>/ews/Exchange.asmx";

    GetAttachmentType request = new GetAttachmentType();

    // Create the response shape.
    AttachmentResponseShapeType responseShape = new AttachmentResponseShapeType();
    responseShape.BodyType = BodyTypeResponseType.Best;
    responseShape.BodyTypeSpecified = true;

    // Add the response shape to the request.
    request.AttachmentShape = responseShape;

    // Identify the attachment IDs to get.
    RequestAttachmentIdType[] ids = new RequestAttachmentIdType[2];
    ids[0] = new RequestAttachmentIdType();
    ids[1] = new RequestAttachmentIdType();
    ids[0].Id = "AAAlAE1BQG1";
    ids[1].Id = "AAAlAE1Bas";

    //// Add the attachment IDs to the request.
    request.AttachmentIds = ids;

    GetAttachmentResponseType response = esb.GetAttachment(request);
    ResponseMessageType[] rmta = response.ResponseMessages.Items;

    I don't know what exactly Attachment ID is and I need to process all attachment , So how do I know which ID to specify?


    http://pradipbobhate.com;
    Wednesday, August 31, 2011 8:44 PM

All replies

  • Hi,

    when you perform a GetItem operation on an item and request the "item:Attachments" property, the result will contain the ids of the attachments. You can then retrieve them using the GetAttachment operation.

    Btw, if you are working with .NET, you should consider using the Exchange Managed API, as it's much simpler to use the the WebServices.

    EWS Managed API - Download: http://www.microsoft.com/download/en/details.aspx?id=13480
    EWS Managed API - SDK: http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx

    Kind regards,
    Henning Krause

    Thursday, September 1, 2011 3:49 PM
  • Hi there,

    I installed Exchange web services managed API however I am unable to include Microsoft.Exchange (Microsoft.Exchange.WebServices.Data) namespace.

    Could you please help me in this?


    http://pradipbobhate.com;
    Friday, September 2, 2011 7:40 PM
  • Hi,

    you need to add the assembly from the path "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"

    Kind regards,
    Henning

    Monday, September 5, 2011 8:30 AM
  •  Hi Henning,

    Thanks for your reply I am able to access Exchange Managed API. Now with these API's could you please provide sample code to download unread attachments.

     


    http://pradipbobhate.com;
    Thursday, September 15, 2011 4:02 PM