static void Main(string[] args) { // init new adapter GmailAdapter gmail = new GmailAdapter(); // create new session and assign username and password GmailSession myAccount = new GmailSession(); myAccount.Username = "******"; myAccount.Password = "******"; // login and retrieve mailbox info GmailAdapter.RequestResponseType loginResult = gmail.Refresh(myAccount); // display mailbox info if (loginResult == GmailAdapter.RequestResponseType.Success) { // show new inbox count Console.WriteLine("New Threads: " + myAccount.DefaultSearchCounts["Inbox"]); // if new threads exist, show the subject of the first one if (myAccount.UnreadThreads.Count > 0) { GmailThread newThread = (GmailThread)myAccount.UnreadThreads[0]; Console.WriteLine("Latest thread subject: " + newThread.SubjectHtml); } } Console.WriteLine("Ended!!!"); System.Environment.Exit(0); }
/// <summary> /// Queries Gmail to get latest mailbox information. /// </summary> /// <param name="session">The <see cref="GmailSession"/> object to query.</param> /// <returns>The <see cref="RequestResponseType"/>.</returns> public RequestResponseType Refresh(GmailSession session) { // bring focus to active session this._session = session; // make sure there is proper login information if (this._session.Username == "" || this._session.Username == null || this._session.Password == "" || this._session.Password == null) { return RequestResponseType.LoginFailed; } // if it's been a while since we logged in, do it again to keep the cookie fresh if (session.LastLoginTime == new DateTime(0) || session.LastLoginTime < DateTime.Now.AddHours(-1)) { if (Login()) { return RequestResponseType.Success; } else { return RequestResponseType.LoginFailed; } } else { if (RefreshDataPack(false)) { return RequestResponseType.Success; } else { return RequestResponseType.RefreshFailed; } } }