Search code examples
c#emailimap

Connect to IMAP server in local


I try to connect Imapclient to the server in local to read mail which I created with MDAEMON (I connected this mail to my outlook). I use 127.0.0.1 with port 143 but it doesn't work. I received :"The host name did not match the name given in the server's SSL certificate" I try to find the resolve in the internet but I still can't find out the way to solve. Please help me. Thank you very much. And my code is:

 private void loginbtn_Click(object sender, EventArgs e)
        {
            using (var client = new ImapClient()) 
            {
                client.Connect("127.0.0.1", 143, false);
                string email = emailbox.Text.ToString().Trim();
                string password = passwordbox.Text.ToString().Trim();
                client.Authenticate(email, password);
                var inbox = client.Inbox;
                inbox.Open(FolderAccess.ReadOnly);
                textBox1.Text = Convert.ToString(inbox.Count);
                recent.Text = Convert.ToString(inbox.Recent);

            }
        }

Solution

  • You need to use:

    client.Connect("127.0.0.1", 143, SecureSocketOptions.None);
    

    The true/false variant of the Connect method's useSsl only affects whether or not the SSL port is being specified.