none
Unable to read attachments from Exchange Server 2010 using EWS Managed API. RRS feed

  • Question

  • Hi,

    I am getting following error while trying to read attachments from Exchange Server 2010 using EWS Managed API. 

    The request failed. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

    Please find my code below. Getting error at fileAttachment.Load

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

                try
                {
                    service.Url = new Uri(ConfigurationManager.AppSettings["EWS"]);

                    service.Credentials = new NetworkCredential("XXXX", "XXX", "XXX");

                    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100));

                    EmailMessage message;

                    foreach (Item item in findResults.Items)
                    {
                        message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));

                        message.Load();

                        if (message.HasAttachments)
                        {
                            foreach (Attachment attachment in message.Attachments)
                            {
                                if (attachment is FileAttachment)
                                {
                                    FileAttachment fileAttachment = attachment as FileAttachment;
                                  
                                    fileAttachment.Load(@"C:\Mohan\Mail\" + fileAttachment.Name);
                                }
                            }
                        }
                    }           
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }



    Mohan Raju

    Friday, December 4, 2015 2:08 PM

All replies

  • Hi,

    This error occured when the connection from the server has exceeded the max connection timeout.

    Your attachment download exceeds the connection timeou because of :

    • network bandwith to the exchange server is too low (most possible reason)

    or

    • the connection timeout is too short (I do not remember the default server connection timeout duration)

    Regards,


    Désiré GOVIN Refresh IT Solutions

    Friday, December 4, 2015 2:41 PM