smiley22 / S22.Imap

A free, easy-to-use and well-documented .NET library component for communicating with IMAP servers
http://smiley22.github.com/S22.Imap/Documentation/
MIT License
211 stars 115 forks source link

ImapClient is only checking one ip address of the gmail service #94

Open RHAD1969 opened 9 years ago

RHAD1969 commented 9 years ago

imap.gmail.com returns several IP addresses (three right now, but the number might vary depending on time and location). You're supposed to try all three. But S22 fails frequently when creating a ImapClient of the gmail service with error:

A socket operation was attempted to an unreachable network [2a00:1450:4013:c01::6d]:993

If one fails in the manner you see, you're supposed to try the next address, but S22 does not have any option to retry.

Can you add this functionality to automatically retry on a different IP address?

See stackoverflow: http://stackoverflow.com/questions/26156820/a-socket-operation-was-attempted-to-an-unreachable-network-2a0014504013c01

jstedfast commented 9 years ago

FWIW to the S22.Imap developers, here's the code I use to do this in MailKit's IMAP implementation:

https://github.com/jstedfast/MailKit/blob/master/MailKit/Net/Imap/ImapClient.cs#L626

Feel free to re-use my logic for this (it's all MIT licensed).

rpanday commented 7 years ago

Answered OP here. http://stackoverflow.com/a/41118069/820597 & reproduced below again.

I had the same problem as OP and did following to retry multiple IP addresses with S22.Imap.dll var ips = Dns.GetHostAddresses("imap.gmail.com"); foreach(var ip in ips) { try { return new ImapClient(ip.ToString(), "993", Email, Password, AuthMethod.Login, true); } catch(SocketException e) //error means server is down, try other IP { //nothing, check next IP for connection } }