In this code, you need to remove the comments and put the credential access to connect to Gmail as a server:
<----- Your GMAIL ID ----->",
"<----- Your GMAIL PASSWORD ----->
The resulting output will be as follows:
Google can block the access by an external application. If it happens, the mail account configured as server will receive the message of access attempt. To allow the access, you must simply configure the Gmail account through the Google web console connecting to https://www.google.com/settings/security/lesssecureapps.
A simpler example is to inject the mail session of WildFly in your own code. The following is a smarter way of sending emails:
@Resource(name = "java:jboss/mail/Default")
private Session session;
...
Message message = new MimeMessage(session);
message.setRecipients(TO, InternetAddress.parse(addresses));
message.setSubject(topic);
message.setText(textMessage);
Transport.send(message);
WildFly has a default configured session. The session contains all the information of the SMTP server, such as the server URL, port, and credentials. This configuration will be seen in the next paragraph.