Fill to: field at using visual basic

I am trying to find a way using my app to go to, 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 ("")

Private Sub WebBrowser2_TitleChange(ByVal Text As String)

If WebBrowser2.LocationName = "Gmail" Then 'page is fully loaded
    WebBrowser2.Document.All("to").Value = ""
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="" 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?
Who is Participating?
Aaronh7996Connect With a Mentor Commented:
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.

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
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.
irkgreenAuthor Commented:
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?
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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 = ""
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
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 = ""
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
irkgreenAuthor Commented:
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 = ""
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?

irkgreenAuthor Commented:
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)

All Courses

From novice to tech pro — start learning today.