GMail IMAP4 using OAuth2

Jun 26, 2013 at 8:43 AM
Hi, here is a working example for using OAuth2 with Gmail:
Imap4Client imap = new Imap4Client();
imap.ConnectSsl("imap.gmail.com", 993);
string stamp = System.DateTime.Now.ToString("yyMMddhhmmss" + System.DateTime.Now.Millisecond.ToString());
string sCmd = "AUTHENTICATE XOAUTH2 " +
                Convert.ToBase64String(Encoding.UTF8.GetBytes(
                "user=" + sEmail + "\u0001auth=Bearer " + sToken + "\u0001\u0001"));
string sResponse = imap.Command(sCmd, stamp);
if (sResponse.StartsWith("*") == false)
                sResponse = imap.Command("\r\n", stamp);
else {
            imap.Mailboxes = imap.GetMailboxes("", "%");
            imap.AllMailboxes = imap.GetMailboxes("", "*");
}