Solved

Logging into Gmail with VB

Posted on 2004-08-28
10
595 Views
Last Modified: 2012-08-13
Hello,

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
        doevents
        For Each gen In ie.document.All
            If gen.id = "login" Then
                MsgBox gen.outerHTML
            End If
        Next

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
0
Comment
Question by:phallout
  • 7
  • 3
10 Comments
 
LVL 1

Expert Comment

by:mkrell
Comment Utility
The gmail login form is loaded in an iframe...
so navigating to "http://gmail.google.com/gmail" returns the parent frame only.

Navigate to:
https://www.google.com/accounts/ServiceLoginBox?service=mail&continue=http%3A%2F%2Fgmail.google.com%2Fgmail

and everything shall work fine.
0
 
LVL 1

Expert Comment

by:mkrell
Comment Utility
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.
0
 

Author Comment

by:phallout
Comment Utility
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
next

Let me know if you need a gmail account to play with.
0
 
LVL 1

Expert Comment

by:mkrell
Comment Utility
well... i'll need a gmail account for soluting your problem.
mail it to: martin2002@web.de
0
 
LVL 1

Expert Comment

by:mkrell
Comment Utility
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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:phallout
Comment Utility
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?

0
 
LVL 1

Expert Comment

by:mkrell
Comment Utility
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.:
https://www.google.com/accounts/ServiceLoginBoxAuth?continue=http%3A%2F%2Fgmail.google.com%2Fgmail&service=mail&Email=[user]&Passwd=[pass]
0
 
LVL 1

Accepted Solution

by:
mkrell earned 500 total points
Comment Utility
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.
0
 
LVL 1

Expert Comment

by:mkrell
Comment Utility
i just forgot:
the script source (i've added some line breaks): http://www.krellmedia.com/downloads/gmail.htm
0
 

Author Comment

by:phallout
Comment Utility
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.

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now