Logging into Gmail with VB


Here is a tricky one for you all.  I am trying to sign into gmail (http://gmail.google.com) with vb.

Gmail uses iframes and extensive javascript to make the pages.

I have tried just about everythign I can think of with no luck.  The last piece I tried makes me think this is almost impossible.   The ID of the login frame is "login"...

Dim ie As New InternetExplorer
Dim iframe As HTMLIFrame
Dim gen As HTMLGenericElement

ie.navigate ("http://gmail.google.com/gmail")
        ie.Visible = True
        do: doevents: loop until ie.busy = false
        For Each gen In ie.document.All
            If gen.id = "login" Then
                MsgBox gen.outerHTML
            End If

The message box (frame code) says that the browser is not supported.

Is there anyway to work with pages like these with the internet explorer object?  I've tried many different ways and cannot get vb to find the input boxes.

Thanks in advance
Who is Participating?
mkrellConnect With a Mentor Commented:
f***... they added a script blocker in to their login box (you have to type in some digits out of an image).
so be not sad... you can forget your project now if you find no other way to login.

but this is what i've done yet:
the login form redirects to "http://gmail.google.com/gmail" (as you may have guessed already) after successfull login... ther is a variable added to the url, but you can remove it to ensure you're not loading an expired session.
the page loaded is the frameset, that loads the script.

i wasn't able to get into these frames by code, so i started analyzing the script.

i learned that they put every view into a single iframe... they're all initially invisible. if you choose a option the associated frame'll be set visible.
(the iframes are surrounded by divs, i guess for positioning them).
we have to find out the corresponding content urls for these iframes now...

but before i'll continue working we have to discuss now if it makes sense, because of this new blocker.

haven't they implemented a pop3 or imap access to the mailbox? if not maybe they'll do it in future times.
it's much easyier to logon to the box an manage it then.
The gmail login form is loaded in an iframe...
so navigating to "http://gmail.google.com/gmail" returns the parent frame only.

Navigate to:

and everything shall work fine.
further comment to my previous post:

all you may have to do is providing a cookie while programmatically clicking on submit button, because this is done by the function:

// This is called when the user logs in to gmail.
// We set a GMAIL_LOGIN cookie with the initial timings.
// The first letter "T" in the cookie value means that the login is not
// completed yet. The main JS will complete logging the timings and update
// the GMAIL_LOGIN cookie. See main.js
function lg() {
  if (login_box_time) {
    var now = (new Date()).getTime();

    var cookie = "T" + start_time + "/" + login_box_time + "/" + now;
    document.cookie = "GMAIL_LOGIN=" + cookie;

(It's called by the function "onlogin" on the above mentured page) on the parent page.
I don't know if there'll be any problems with the login procedure.

So if there are, fill the "document.cookie" value with the data of the above function by using your ie object.
After that let your program click on "submit" button.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

phalloutAuthor Commented:
Well I don't believe it.   Your first post worked.  I tried that same thing yesterday but after loggin in, it took me to a page showing me all the google services I was eligible for with my "google account".  And if I followed the Gmail link... it took me right back to the main login page.  I don't know if I just got the URL wrong or if google change their logon procedure since last night but... now it works.

I have a similar problem now though.  I now need to click the "compose mail" link after logging in.  Then fill out the fields to send a message.  I can do all the filling if I could just get to the actual page(s)

Why doesent something like this work?  Is the iframe technically not part of the ie.document?

dim iframe as htmliframe
for each iframe in ie.document.all
     if iframe.id = "login" then
          'now search through iframe.document and do what is needed.
     end if

Let me know if you need a gmail account to play with.
well... i'll need a gmail account for soluting your problem.
mail it to: martin2002@web.de
ok I build an example application for you that solves the automatic login process for now.
1. It searces for the IFRAME
2. Then it navigates to the desired IFRAME src
3. Now it fills in the login form, adds the cookie to document.cookie an submits the form

download it: http://www.krellmedia.com/downloads/gmail.zip

ok... now I need the login info to continue with the task
phalloutAuthor Commented:
Well wouldn't you know it.  As it turns out... what I'm trying to accomplish has already been done... Sort of.  Although I'll continue with my project because I can personalize it how I want/need it.  Filling out the compose mail form can be done by setting variables in the url.  Then the user will send the email.

I got to looking around and after you login... all the pages from that point are made in the browser with a giant java script.  So I guess, if I were to access the ie.document of the page, I would be accessing the java script and not the actual HTML that has been parsed in my window?

by loading such a page you can easylie access the functions published to that page...

as you may see, they're stored in a hidden frame at the right border of the navigator window. this frame has the name "js" and is accessed by referring to "top.js" in the code. it's current source is: "/gmail?view=page&name=js&ver=193369f44cfe6a16"

example url for the send mail form is: "http://gmail.google.com/gmail?view=cm&zx=193369f44cfe6a16452064766&fs=1"

the problem is that the url's may alter from session to session.
to accomplish that you may have to analyze the whole script, to get information about functions generating the page content and then find a way to let them extract the urls for you.

i'll provide you further information tomorrow... for now i'm blown up with server errors by the gmail pages.

as a next step i would try finding a way of getting the content of the page that is called by the login form, e.g.:
i just forgot:
the script source (i've added some line breaks): http://www.krellmedia.com/downloads/gmail.htm
phalloutAuthor Commented:
Hmm... I tried loggin in and didn't see the blocker.  I did type in my password wrong yesterday and it asked for the password and to type the numbers shown in the box... that might be a password-cracking blocker to stop brute force password cracking of accounts.

I started this project to make gmail my default email browser and to have it fill in the forms if mailto links were clicked.  I found the registry entries rather easily and started playing with them and thought it would be a rather easy project to undertake. :)

Google has the "Gmail notifier" which sits in the taskbar and checks your email and notifies you if you have any new emails.  It also allows web mailto links to be auto filled in but I noticed it does not work for all possible fields and it cuts off the subject to just the first word.

I was going to make toe app and keep adding features to it but... I donno... that wheel has been invented several times now. :/  but most are half-assed approaches... even Google's own tool.

There is an app that will take your gmail emails and act as a pop3 server so you can check them from any email app.  I don't know how it works though... gmail is still changing so much that the app could stop working any day.

You've been enough help that I should be able to figure out the rest should I continue.  I'm using gmail notifier for its email checking (which fails every couple tries).  Even though it doesn't work that great on mailto links, I don't click that many anyway.  I just started my second year of college and should have some new and "required" programming tasks to occupy my time here pretty soon so it's probably best that I at least delay the project.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.