Fill to: field at gmail.com using visual basic

Posted on 2005-03-19
Medium Priority
Last Modified: 2013-12-26
I am trying to find a way using my app to go to gmail.com, compose a new mail and fill the to: field with an email address.  Then the browser would then be presented to the user.  Right now i am using MS internet controls and i can open the compose page.  I can even log into gmail using this handy link i found.  I also wait for the page to fully load and then i try to fill in the to field and nothing!

I would much rather generate a link that i can open in the user's default browser.  As it stands now i hafta use the WebBrowser1 object on a form.  

here is the code:


'goes to gmail, logs in (MYPASSWORD AND MYEMAIL), goes to compose new mail
frmEmail.WebBrowser2.Navigate ("https://www.google.com/accounts/ServiceLoginAuth?service=mail&continue=https://gmail.google.com/gmail%3fview%3dcm&Email=MYEMAIL&Passwd=MYPASSWORD&PersistentCookie=no")

Private Sub WebBrowser2_TitleChange(ByVal Text As String)

If WebBrowser2.LocationName = "Gmail" Then 'page is fully loaded
    WebBrowser2.Document.All("to").Value = "test@test.com"
End If

End Sub


the following is the html of the compose email page:

<FORM class="cf cn" accept-charset=utf-8 onsubmit="return false" action=/gmail?&amp;ik=f0f11be10c method=post target=hist encType=multipart/form-data><INPUT type=hidden name=view><INPUT type=hidden name=rm><INPUT type=hidden name=th><INPUT type=hidden name=draft><INPUT type=hidden name=cmid><INPUT type=hidden name=at>
<TABLE class=ctb cellSpacing=0 cellPadding=0 width="100%">
<TR id=cft bgColor=#c3d9ff height=2>
<TD class=tl>
<TD class=tr>
<TD colSpan=2>
<DIV class="cg " id=rc_compose></DIV>
<TD id=sd_compose_top colSpan=2>
<DIV class=cd><SPAN class=h id=nc_compose style="FLOAT: right"><IMG height=16 src="http://gmail.google.com/gmail/images/tearoff_icon.gif" width=16></SPAN><BUTTON id=send onkeydown="return top.js._CM_OnSendButtonKeyDown(window,this,event)" onblur="return top.js._CM_OnSendButtonBlur(window,this)" style="PADDING-RIGHT: 2em; PADDING-LEFT: 2em; PADDING-BOTTOM: 0px; PADDING-TOP: 0px" tabIndex=1><B>Send</B></BUTTON> &nbsp;<BUTTON id=d style="PADDING-RIGHT: 1em; PADDING-LEFT: 1em; PADDING-BOTTOM: 0px; PADDING-TOP: 0px" tabIndex=1>Save&nbsp;Draft</BUTTON> &nbsp;<BUTTON id=x style="PADDING-RIGHT: 1em; PADDING-LEFT: 1em; PADDING-BOTTOM: 0px; PADDING-TOP: 0px" tabIndex=1>Discard</BUTTON> &nbsp; &nbsp; <SPAN class=sl id=spck_compose style="FONT-SIZE: 90%"><SPAN class=lk>Check&nbsp;spelling</SPAN></SPAN><SPAN id=cspd_compose style="DISPLAY: none"> - <SPAN class="lk sl" id=cspck style="FONT-SIZE: 90%">Done</SPAN></SPAN></DIV>
<TR style="PADDING-TOP: 5px">
<TD colSpan=2>
<DIV class=ci id=cmhdr_compose>
<DIV class=cd>
<TABLE cellSpacing=2 cellPadding=0 width="100%">
<TR id=0row_compose vAlign=top align=right>
<TD style="WHITE-SPACE: nowrap"><B>To:</B>
<TD width="100%" colSpan=2><TEXTAREA id=to_compose style="WIDTH: 100%" tabIndex=1 name=to match_fn_id="2"></TEXTAREA>
<TR id=1row_compose style="DISPLAY: none" vAlign=top align=right>
<TD style="WHITE-SPACE: nowrap"><B>Cc:</B>
<TD width="100%" colSpan=2><TEXTAREA id=cc_compose style="WIDTH: 100%" tabIndex=1 name=cc match_fn_id="2"></TEXTAREA>

Any thoughts?  Is there a better way to do this?
Question by:irkgreen
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
LVL 11

Expert Comment

ID: 13594470

I don't know how to do it, but since noone responded in the past two days, maybe this alternative could be usefull to you.

You could download gpopper from http://imizzy.com/gpopper/
It is a program which is already doing what you want and simulates POP3 and SMTP servers so you can access GMail in Outlook or other mail clients.
So, to send or read gmail messages from VB application, you could install gpopper, create a gmail account in Outlook and then use MAPI Controls to read or compose messages using this gmail account.

Author Comment

ID: 13594685
I should have explained some background of the program.  The program I am creating already opens up Outlook when you double click an email.  But I wanted to add a function that if you hold down shift and doubleclick the email it would open up your browser to your favorite html email.  I plan trying this for hotmail, aol, yahoo, and gmail.

By the way: gmail already supports POP forwarding (it is in your gmail settings).  In fact that is what i use at home.  It basically allows you to check gmail using any supported email client.

I'd also like to avoid using any 3rd party software.

Perhaps someone has done this for another html based email?

Expert Comment

ID: 13635867
find a better event to hook into rather than the title change; often on my browser, the title changes while the page is still blank

use something like FireFox's DOM inspector to find out what the TO field is actually called. you might find yourself looking up another way:

Dim coll as Object
coll = WebBrowser1.Document.All.Tags("INPUT")
Dim i as Integer
For i = 0 to coll.length-1
  If coll(i).name = "gmailTO" Then coll(i).value = "bill@microsoft.com"
Next i

of course, you need to read the html source and find out what the input field is actually named as.. afaicr, controls can only be referenced like Document.All.Tags("INPUT").Children("gmailTO") if the class or ID is gmailTO. name is not applicable to identifying a document element in a collection
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


Expert Comment

ID: 13635875
sorry, i didnt realise you'd posted the html of what i'd find at gmail..

int he document complete, try:

Webbrowser1.Document.All.Tags("TEXTAREA")("to_compose").Value = "bill@microsoft.com"

Expert Comment

ID: 13635880
or even WebBrowser1.Document.All("to_compose").Value

remember; you dont use the name=to, you use the id=to_compose to pick your element out of the collection

Author Comment

ID: 13636377
I changed the event to a comand button click just to be sure that the page is fully loaded, for testing purposes.

i tried both
Webbrowser2.Document.All.Tags("TEXTAREA")("to_compose").Value = "bill@microsoft.com"
WebBrowser2.Document.All("to_compose").Value = "test"

and both produced "object variable or with block not set" errors

I tried a few other variations too, but I know visualbasic but i really dont understand how to read the html for what i am looking for.

Using DOM explorer i found:

Node name is TEXTAREA
Node type = 1

<TEXTAREA id="to_compose" name="to" wrap="soft" rows="2" style="width: 100%;" tabindex="1"/>

the tree to get from the top documnet to the textarea was huge. To_compose is inside of cmhdr_compose whichis inside of cm_compose and so on...

Do i need to ID these other objects?  Do i need to do something with rows?


Accepted Solution

Aaronh7996 earned 1000 total points
ID: 13655669
The gmail notifier has a option to use gmail for mailto: links.  When mailto: has been run you get this url:
The "bah" in the url is what I typed in the run command.

Author Comment

ID: 13655811
that's perfect aaron7996!!!

It works even without gmail notifier installed

Now i need to repeat this for hotmail, yahoo, aol, etc... but those should be easier (i hope)


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

800 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