Search code examples
c#gmailwebclient

WebClient: Logging into Gmail


I've been trying to log into Gmail using:

WebClient Web = new WebClient();
Web.Credentials = new NetworkCredential(Email, Password, "https://mail.google.com");

and then browse the email using IHTMLDocument2 interface by getting the id associated to each email, building up the url, navigating to that url and using DownloadString method, pass the HTML content to the IHTMLDocument2 interface.

The problem is that google does not accept the credentials that I send so I can never log in. However, after a few attempts I saw that this activity has been monitored by Google as I saw a notification about that on the actual email account.

I would like to know how this problem can be solved or is it possible at all to log into Gmail using WebClient? if yes, how exactly ?


Solution

  • Use Fiddler to observe what the browser does. Fiddler can capture HTTPS traffic. A Google login is more complex than you might think.

    The Credentials property has no effect on web forms. There is no standardized way to have a login form in HTML. WebClient cannot possibly know how the Google login form works. It cannot possibly automate this for you.