Reading Emails using GMail in C#

Download source code

oAuth.AuthUrl = "https://accounts.google.com/o/oauth2/auth";
oAuth.TokenUrl = "https://accounts.google.com/o/oauth2/token";
oAuth.RedirectUrl = "http://localhost";
oAuth.ClientID = "421475025220-6khpgoldbdsi60fegvjdqk2bk4v19ss2.apps.googleusercontent.com";
oAuth.ClientSecret = "_4HJyAVUmH_iVrPB8pOJXjR1";
oAuth.Scope = "https://mail.google.com/";

imap.Server = "imap.gmail.com";
imap.Port = 993;
imap.UseTls = ClientTlsMode.Implicit;

imap.UserName = "user...@gmail.com";

imap.Authorization = oAuth.GetAuthorization();

imap.Open();

var mailboxes = imap.GetMailBoxes();

for (int i = 0; i < mailboxes.Length; i++) {
    string item = mailboxes[i].ToString();
    tvFolders.Items.Add(item);
}
 

Add Feedback