Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I 'm working on an mvc application to fetch emails from my gmail account using MailKit, on my local computer it works perfectly. However, when uploading it on the host i get the "A socket operation was attempted to an unreachable network". I don't have ssl enabled on the host. all suggestions are appreciated I have crawled the web and tried all the solutions even S22.Imap.dll but still same error.

C#
    using (var client = new ImapClient())
{
    using (var cancel = new CancellationTokenSource())
    {
        // For demo-purposes, accept all SSL certificates
        client.ServerCertificateValidationCallback = (s, c, h, e) => true;

        var ips = Dns.GetHostAddresses("imap.gmail.com");
        try
        {
            client.Connect("imap.gmail.com", 993, true, cancel.Token);
        }
        catch
        {
            foreach (var ip in ips)
            {
                try
                {
                    client.Connect(ip.ToString(), 993, true, cancel.Token);
                }
                catch (SocketException e) //error means server is down, try other IP
                {
                    //nothing, check next IP for connection
                }
            }
        }

        // Note: since we don't have an OAuth2 token, disable
        // the XOAUTH2 authentication mechanism.
        client.AuthenticationMechanisms.Remove("XOAUTH2");

        client.Authenticate(username, password);}}


Is this SSL Problem ? appreciate all the help I can get

Regards,

What I have tried:

everything found on google
even tried S22.Imap.dll, same problem.
Posted
Comments
Graeme_Grant 28-Jul-17 2:01am    
Is there an inner exception? The inner exception should give the reason.
mrkeivan 28-Jul-17 3:57am    
nope, nothing that's all i get. I have searched for days, all people suggested was to try different IPS, and I did but still the same.
Richard MacCutchan 28-Jul-17 5:31am    
"A socket operation was attempted to an unreachable network"
This suggests that the target IP address cannot be reached from the system that is running this code. Could be blocked by the firewall, or just not connected to the outside world.
mrkeivan 28-Jul-17 15:55pm    
Don't have access to the actual server since it's a shared host but asked them to ping the address and let me know.
Dave Kreskowiak 28-Jul-17 9:17am    
This sounds like it's a question for your hosting provider. They may have the outbound ports blocked preventing you from connecting to outside email servers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900