Gmail runs TLS/SSL secured IMAP server on imap.gmail.com, port 993. Following C# code demonstrates how to connect to it using Rebex Secure Mail or Rebex Secure IMAP:
// connect and log in
Imap imap = new Imap();
imap.Connect("imap.gmail.com", 993, null, ImapSecurity.Implicit);
imap.Login(username, password);
// process messagess...
// logount and disconnect
imap.Disconnect();