Logging into Gmail with VB

Posted on 2004-08-28
Last Modified: 2012-08-13

Here is a tricky one for you all.  I am trying to sign into gmail ( 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 ("")
        ie.Visible = True
        do: doevents: loop until ie.busy = false
        For Each gen In ie.document.All
            If = "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
Question by:phallout
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3

Expert Comment

ID: 11926848
The gmail login form is loaded in an iframe...
so navigating to "" returns the parent frame only.

Navigate to:

and everything shall work fine.

Expert Comment

ID: 11926897
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.

Author Comment

ID: 11927662
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 = "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.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 11929453
well... i'll need a gmail account for soluting your problem.
mail it to:

Expert Comment

ID: 11930100
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:

ok... now I need the login info to continue with the task

Author Comment

ID: 11935649
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?


Expert Comment

ID: 11936575
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: ""

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.:[user]&Passwd=[pass]

Accepted Solution

mkrell earned 500 total points
ID: 11944980
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 "" (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.

Expert Comment

ID: 11945030
i just forgot:
the script source (i've added some line breaks):

Author Comment

ID: 11947487
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.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
message box in access 4 52
Prevent user closing word document opened with VB6 6 84
MS Access 03, TransferText, decimal places 8 85
VBA - If Bookmark = "XXBOOKMARKXX" then 15 51
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question