Is it possible to update this code snippet, in order to reflect the authentication required by Gmail. When I run this program using smtp.gmail.com as an SMTP server, an error is reading java.net.ConnectException
Don't manually connect to an SMTP server, but use JavaMail instead. It's designed for this kind of thing, and if you search a bit you'll find plenty of examples about getting JavaMail to connect to Google.