aenetmail icon indicating copy to clipboard operation
aenetmail copied to clipboard

IOException

Open elvinyang opened this issue 12 years ago • 11 comments

Code: var imap = new ImapClient("imap.gmail.com", "[email protected]", "pwd", AE.Net.Mail.ImapClient.AuthMethods.Login, 993, true); imap.NewMessage += (sender, e) => { var newMsg = imap.GetMessage(e.MessageCount - 1); Console.WriteLine("Total email: {0}, current subject {1}.", e.MessageCount, newMsg.Subject); }; After the NewMessage event is triggered, it'll later get an exception:

System.IO.IOException was unhandled Message=Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. Source=System StackTrace: at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.Stream.ReadByte() at AE.Net.Mail.TextClient.GetResponse() in C:\Users\elviny\Desktop\andyedinborough-aenetmail-7ed7bf1\TextClient.cs:line 106 at AE.Net.Mail.ImapClient.<>c__DisplayClass4.<TryGetResponse>b__3(Object _) in C:\Users\elviny\Desktop\andyedinborough-aenetmail-7ed7bf1\ImapClient.cs:line 135 at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() InnerException: System.Net.Sockets.SocketException Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond Source=System ErrorCode=10060 NativeErrorCode=10060 StackTrace: at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) InnerException:

Inner exception: {"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"}

Stack: at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

elvinyang avatar May 30 '12 06:05 elvinyang

I also have this issue! This renders IDLE useless (after the first mail). Any suggestions?

NadavK avatar Jun 25 '12 07:06 NadavK

Hello I am having the same problem. It seems commenting out stream.ReadTimeout = 10000 in Utilities.cs fixes the problem. I wouldn't know why it times out in the first place though, 10000ms seems like a reasonable timeout value...

smiley22 avatar Aug 02 '12 20:08 smiley22

I believe the problem is that ReadToEnd is being called on the network stream (for instance in the MailMessage Load method), which is then setting the read timeout value to 10000ms. The timeout would then be triggered when the client goes into IDLE mode waiting on the socket to receive notifications from the server.

What's the purpose of setting a ReadTimeout value in the first place in the ReadToEnd and ReadLine methods?

smiley22 avatar Aug 03 '12 09:08 smiley22

I tried smiley22's fix -- I commented out the lines that set the timeout to 10000, it worked for a few minutes. Then I tried setting it to -1 instead of 10000 and it seems to be working now.

brian32768 avatar Aug 03 '12 18:08 brian32768

I am also having this issue. If I try with fix mentioned by smiley22 I get:

Exception of type 'System.OutOfMemoryException' was thrown.

Utilities.cs line 27. mem.WriteByte(b);

zlajson avatar Aug 16 '12 12:08 zlajson

I have a problem as zlaja

anbinhtrong avatar Aug 30 '12 09:08 anbinhtrong

My code: var fromAddress = new MailAddress(from); var toAddress = new MailAddress(to); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, Timeout = -1, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, frompw) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); }

This code run with no problem on my home machine but when I run it on another machine which have a connection to proxy server, it's not work. I'm not sure the problem is due to proxy or not but it may be a clue.

Anyone get the same situation?

nambtt avatar Nov 08 '12 03:11 nambtt

+1 Having the same problem with IDLE support....

Then I tried setting it to -1 instead of 10000 and it seems to be working now.

That didn't work for me :(

JustDerb avatar Mar 16 '13 22:03 JustDerb

+1 Also experiencing this issue with Gmail Mailbox.

benfoster avatar May 29 '13 11:05 benfoster

Found this issue (so far, only just started) in Hotmail changed timeout to -1 as above and that worked for me.

StephanosSteer avatar Nov 08 '14 13:11 StephanosSteer