aenetmail
aenetmail copied to clipboard
IOException
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)
I also have this issue! This renders IDLE useless (after the first mail). Any suggestions?
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...
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?
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.
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);
I have a problem as zlaja
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?
+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 :(
+1 Also experiencing this issue with Gmail Mailbox.
Found this issue (so far, only just started) in Hotmail changed timeout to -1 as above and that worked for me.