Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)....

HTML
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).
HTML
<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>
            </div>
        </div>
    </div>
</div>

I first tried invoking click ( InvokeMember("click") ) on the inner DIV containing the SEND text:
HTML
<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?

++Thanks
Posted
Comments
South 305 10-Jan-12 18:18pm    
@shoputer
------------------
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

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Jan-12 14:52pm    
Makes sense, useful link; I voted 5.
--SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900