I already spent some time few years ago to figure that out and now I spent this time again.
So here's the short code snippet with an example how to send mail using Java Mail and GMail.
First, pom.xml. Include the following dependencies:
And now the code:
And the thanks goes here.