We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

EWS FetchMessage - Underlying connection closed: An unexpected error occurred on a recieve

Hi,

We have been using Email for .Net for some time and have progressed sufficiently in what we want to do, simply download message details for processing in a another application. However at some point in the last week this has stopped working. I have updated to the latest version but I still get the same error.

My code

Dim credential As System.Net.NetworkCredential = New System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text, txtDomain.Text)

Dim client As Aspose.Email.Exchange.IEWSClient = EWSClient.GetEWSClient(txtExchangeServer.Text, credential)
Dim msgCollection As ExchangeMessageInfoCollection = client.ListMessages(client.MailboxInfo.InboxUri)

’ loop through the collection to display the basic information
For Each msgInfo As ExchangeMessageInfo In msgCollection

Dim strMessageURI As String = msgInfo.UniqueUri

'Now get the message details using FetchMessage()
Dim msg As Aspose.Email.Mail.MailMessage = client.FetchMessage(strMessageURI)
If Not msgInfo.IsRead Then
Dim strMsgInfo = “Subject: " & msg.Subject & " From :” & msg.From.ToString() & " To: " & msg.To.ToString & " Body : " & msg.Body
lstMessages.Items.Add(strMsgInfo)
client.SetReadFlag(strMessageURI)

End If

Next msgInfo

This works fine to the point of accessing the EWSclient, I can see number of message and details within the MsgInfo, but everytime I access FetchMessage() I recieve

{“The underlying connection was closed: An unexpected error occurred on a receive.”}
InnerException
{“Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.”}

any ideas, like I said this has been working perfectly for months now!

Cheers

Andy.


I have just tried this using .Net 4 and it has worked as expected. The problem being I need this to work for .Net 2.0.

Hi Andy,

Thank you for writing to Aspose support team.

I have investigated this issue at my end using the latest version of Aspose.Email for .NET 4.8.0 and was unable to observe any such exception as you have specified. The messages are retrieved fine with both target .NET frameworks 2.0 and 4.0. Could you please share if you are using the latest version of Aspose.Email for .NET at your end?

Hi Kashif, thanks for your reply. It looks as though the problem was my end. As I said I have had this working for months and suddenly just gave up. The best explanation I have got so far is the the cert severs where not configured properly. If I do eventually get a proper explanation I will make sure I post back here.

Cheers
Andy.

Hi Andy,


Thank for providing feedback. Please feel free to write us back if you have any other query related to Aspose.Email.

When talking to our network team it seems as though there was not much done if anything that caused my app to start working again. Funnily enough it has now decided to stop working again, and apparently nothing else has happened!


I am at a bit of a loose end as to why this has started to become a bit intermittenment.

Here is my latest stack trace if anybody can shed some light on this I would be most appreciative!
Something I have found quite strange (highlighted) is the call that causes the failure is incomplete within the stack.
Viewing the code above you can see this should read Aspose.Email.Exchange.FetchMessage(String)


at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Aspose.Email.Exchange.Schema.Exchange_2013.ExchangeServiceBinding.GetItem(GetItemType GetItem1)
at . .FetchMessage(String )
at ConnectExchange.Form1.Button1_Click(Object sender, EventArgs e) in E:\Dev\VB Projects\2005 ConnectExchange\ConnectExchange\Form1.vb:line 30
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at ConnectExchange.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Hi Andy,

Thank you for writing back to us.

I am afraid to share that I was again unable to reproduce this issue at my end while testing with both Exchange Server 2010 and Exchange Server 2013. There is no such exception raised as been mentioned by you. In order to investigate this issue further, could you please arrange a test account for us on your server that we can use for reproducing the issue at our end? This will help us assist you accordingly. Also, please share your Exchange Server details with us i.e. version, service pack installed, etc.

Hi Kashif,

I am nearly 100% certain that Aspose is not the problem here and that somewhere along the network to Exchange etc etc is the cause of this.
Whilst I am trying to get hold of of the team to provide me the info you are after, as a work around would there be any other way using Aspose in which I could get the Email body from the message, without using the FetchMessage method that is causing me this problem.

All I need to get is just the Message details from each unread mail. I can get the majority by utilising ExchnageMessgeInfo but this does not hold the ‘Body’ of the email.Is there any further option available to me in which I could get the ‘Body’ of each email in the mailbox.

Cheers

Andy.

Hi Andy,


I am afraid that there is no other alternate way to get message body from Exchange server without using FetchMessage. You may please provide some test account to re-produce this scenario here as it will help us to observe the issue and provide assistance as soon as possible.

Hi Kashif,


I am afraid I am not going to be able to provide any test account as I am working on a closed development system. We are on Exchange version 2010sp3ru5. Yesterday we thoroughly tested the proxy settings and the fact that I can connect to Exchange and see all available messages via ExchangeMessageInfoCollection we are sure that this is fine and working. So the problem must be at the server side refusing these connections?

Just as another thought, is there anyway I can use Aspose to connect to the Exchange server without using the EWS uri. What I am actually trying to implement does not really require access form outside the organisation.

Thanks again

Andy.

Hi Andy,


Thank you for sharing the feedback with us.

You may consider accessing your Exchange server using our POP3 and IMAP clients as well. This requires the mentioned services to be enabled on your Exchange server. Please set the host information of these clients to those of your exchange server and provide the credentials for accessing the mailbox. Feel free to contact us in case you need further assistance in this regard.

Hi Kashif,


Thanks for the info…

Due to Christmas period decided I was getting fed up waiting on our apps guys to debug this form me so decided to take things into my own hands…

First thing I did was log into the Exchange Server… thought I would check out the EWS logs… Didn’t even get that far. Saw the system partition had absolutely no space at all. Deleted a few old profiles and freed up some space. First test worked as expected. Why I didn’t do this sooner!!!

So, note for future… Problems with FetchMessage… Check sys partition space!!

Thanks for your help, and happy new year.

Andy.


Hi Andy,


We are glad to know that your issue is resolved and please feel free to write us back for any further query.

Happy new year to you as well. :slight_smile: