0 votes

Hi,
I'm downloading body of each email using following method

imap.GetTextByUID(info.BodyStructure.Html);

So basically I downloaded all headers and inside the for loop I'm calling above method to fetch body content. But after iterating around 1000 times it is throwing following error.

Limilabs.Client.ServerException: Last network operation failed.
at Limilabs.Client.ClientBase.()
at Limilabs.Client.ClientBase.(Byte[] )
at Limilabs.Client.ClientBase.SendCrLfWithLog(Byte[] bytes)
at Limilabs.Client.ClientBase.Send(String command)
at Limilabs.Client.IMAP.Imap.(ImapCommand )
at Limilabs.Client.IMAP.Imap.(ImapCommand , Boolean )
at Limilabs.Client.IMAP.Imap.SendCommand(String command, Boolean throwException)
at Limilabs.Client.IMAP.Imap.(String , Object[] )
at   .(List`1 ,    )
at   .(MimeStructure )
at   .(MimeTextStructure )
at Limilabs.Client.IMAP.Imap.GetTextByUID(MimeTextStructure structure)

I think gmail IMAP is rejecting after many calls. So is there any solution to do that.

Thanks,
Sarathi

by (1.4k points)

1 Answer

0 votes

"Last network operation failed" exception means that you ignored previous exception, that was thrown and tried to issued another IMAP command.

You need to look at the previous exception, to know what happened exactly.

There is a good chance that:

  • your connection was cut and you must simply recreate Imap instance, connect and try again.
  • Google disconnected you, because of too many operations.

Please check the FolderStatus.Throttled property (FolderStatus is returned by Imap.Select method). This property indicates that your IMAP requests are being throttled. In this case, your application should back off and perform fewer requests for that user.

Also consider looking at the logs.

by (297k points)
Here is the previous exception I'm getting.


Limilabs.Client.ServerException: Tried to read a line. Only '' received. Please make sure that antivirus and firewall software are disabled or configured correctly. ---> System.Exception: Tried to read a line. Only '' received. ---> System.IO.IOException: 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. ---> System.Net.Sockets.SocketException: 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
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
...
   at Limilabs.Client.IMAP.ImapResponse.(Stream )
   at Limilabs.Client.IMAP.Imap.(ImapResponse )
   at Limilabs.Client.IMAP.Imap.(String , Boolean )
   at Limilabs.Client.IMAP.Imap.ReceiveResponse(String tag)
   at Limilabs.Client.IMAP.Imap.(ImapCommand , Boolean )
   at Limilabs.Client.IMAP.Imap.SendCommand(String command, Boolean throwException)
   at Limilabs.Client.IMAP.Imap.(String , Object[] )
   at   .(List`1 ,    )
   at   .(MimeStructure )
   at   .(MimeTextStructure )
   at Limilabs.Client.IMAP.Imap.GetTextByUID(MimeTextStructure structure)
It means that the connection was cut. Recreate Imap instance and try again
But I'm getting this exception every time after 1000 requests done, Shall I make it within try-catch block and whenever I will get this error I need to recreate IMAP instance? Or is there any limitation in google imap to fetch the body. I mean I need to confirm this if google is not allowing to give further request after n number of requests.
Yes, you need to recreate and reconnect on exception - there is no other way. Please check the FolderStatus.Throttled property, I described earlier, to see if Gmail wants you to back off. Consider using bulk method (they take a range of uids). Please have in mind that it's Gmail that is imposing some limits on you not Mail.dll.
...