If I remember correctly, automating the use of GMail is a technical violation of their terms of service. It's not something that their likely to take action against you for, as many other people/companies do do this as well.
From Google Terms of Service
5.3 You agree not to access (or attempt to access) any of the Services by any means other than through the interface that is provided by
Google, unless you have been specifically allowed to do so in a
separate agreement with Google. You specifically agree not to access
(or attempt to access) any of the Services through any automated means
(including use of scripts or web crawlers) and shall ensure that you
comply with the instructions set out in any robots.txt file present on
Do you actually need to login to the google site in order to do this?
If you wanted to, you could definitely use a third party client, and, it will probably run faster than to access it through the UI.
I'm sure that you could do something similar with Java and a third party client, so, I'll give you how I normally handle email using outlook. I typically setup a folder for each application that I need to validate the emails that were sent. From there, I have my code access the client and then the specific folder. When in the folder, I attempt to Match the From, To, CC, Subject, and body with my expected values. If I don't need to verify much, I'll just pass these in as parameters. If I'm having to validate all of the information, I would typically create some strings that I could set to the values of what I need to check and then attempt the match. This is easier to do than through the UI as well.