Search code examples
c#apioutlookgmailgmail-api

C# automatic login to gmail/hotmail via web browser


I`m trying to do something like LassPass, but as a desktop application. I use VS 2013, C# and Windows Forms.

I have my user email and password for gmail or outlook and I want to click a button in my desktop program to open my local default browser ie., Chrome/Firefox with appropriate link. I want to be automatic login in service(gmail/outlook). I want to ask if I have to use appropriate API or only some kind of link (https://mail.google.com/login="userlogin",password="userpassword") will be good.

I see a gmail API, there is how to send a mail, but i cannot find how to log into service.

Are in Gmail or Outlook API functions which can help me?


Solution

  • You are looking for Selenium

    once you have it setup you can do something like

    using OpenQA.Selenium.Firefox;
    using OpenQA.Selenium;
    
    class Test
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("https://www.gmail.com/");
            IWebElement query = driver.FindElement(By.Id("Email"));
            query.SendKeys("[email protected]");
            query = driver.FindElement(By.Id("next"));
            query.Click();
            // now you just have to do the same for the password page
    
            driver.Quit();
        }
    }
    

    You may find these links helpful: