Click here to Skip to main content
13,048,011 members (74,259 online)
Rate this:
Please Sign up or sign in to vote.
See more: , +
I'm trying to FORWARD and email from GMAIL using the WebBrowserControl (C#).

-I am able to open the Gmail INBOX page on the WebBrowserControl...
-I am able to OPEN the specific email (among the others on the inbox) that I need to forward...
-I am able to find and click the FORWARD link to start working with the email fields (TEXTS)...
-I am able to add/insert the email that I would like to send TO...
-I am able to add/edit the content of the email body...

However, now that I am done with the email I CAN'T SEND IT. I need to invoke/click the SEND button but Gmail uses DIV instead of BUTTONS and the regular CLICK does not work.

This is what I did so far. Since most of the DIVs do not have ID, I iterate through all the DIVs inside the Gmail MAIN FRAME (canvas_frame)....

webIE.Document.Window.Frames["canvas_frame"].Document.Body.GetElementsByTagName( "div" );

...and with a regular expression I was able to find the right DIV that contains the text(SEND) that I need to click. Here is the sample on how GMAIL encapsulates the HTML 'SEND' BUTTON = DIV (the same apply to most of the buttons like SAVE NOW, DISCARD, etc).
<div id=":j5" class="J-K-I J-J5-Ji Bq L3" role="button" tabIndex="1" unselectable="on">
    <div class="J-J5-Ji J-K-I-Kv-H" unselectable="on">
        <div class="J-J5-Ji J-K-I-J6-H" unselectable="on">
            <div class="J-K-I-KC" unselectable="on">
                <div class="J-K-I-K9-KP" unselectable="on"> </div>
                <div class="J-K-I-Jz" unselectable="on">Send</div>

I first tried invoking click ( InvokeMember("click") ) on the inner DIV containing the SEND text:
<div class="J-K-I-Jz" unselectable="on">Send</div>

...but unfortunately did not work, then I tried invoking click on all and any of the DIVs (Parent/Children) of the above HTML code with no luck at all.

Any IDEA/ADVICE on how can I get to SEND the email?

Posted 10-Jan-12 4:25am
South 305 10-Jan-12 18:18pm
Yes, kinda automate, and the main reason on why I decided to use the WebBrowserControl instead of any other API is that I need to keep the history on the account as if I did (answered/forwarded) by myself. I mean the original email and the answered threads (as Gmail groups the emails).

I know that everything depend on the Gmail Layout that is why I am using the old look and is worthy. I can login on a gmail accounts and with one click I can send a customize answered (1 by 1) to lots of customers. And as I mentioned, keeping the history for reference and organization matters.

I am familiar with the GMAIL SMTP and I use that with some other C# apps but in this case I really need to hit the SEND (DIV)... lol

Thanks anyways...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all, this is probably not the kind of answer you'd expect.

As far as I understand your problem, you're trying to automate the process of forwarding an e-mail, isn't it? What are you doing in case Google decides to change their layout?

In my opinion it would be better and hopefully easier if you're trying to connect to your GMail account via IMAP, querying for the message you want to forward, download and modify it and finally resend it via SMTP (through Google Mail).

There is already a SMTP client[^] built into the .NET framework. Unfortunately you have to look for an external library which lets you browse your inbox via IMAP. I found this one[^]. I don't know if there are others, probably yes.

Just my thoughts.
SAKryukov 10-Jan-12 14:52pm
Makes sense, useful link; I voted 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 10 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100