In most application I build it is very convenient to sent out a mail in certain situations. Last project I had to send out a mail from a JEE application that was deployed at JBoss 7.1. In case of a JEE application it is very common to define the mail service in your container, JBoss 7.1 in this case.
To configure GMail as the mail server in JBoss you have to modify the main configuration file in two places. The main configuration file for a standalone installation is ‘$JBOSS_HOME/standalone/configuration/standalone.xml’ and for a clustered setup ‘$JBOSS_HOME/domain/configuration/domain.xml’.
The first part that has to be modified is:
<mail-session jndi-name="java:jboss/mail/Default"> <smtp-server outbound-socket-binding-ref="mail-smtp"/> </mail-session>
Modify the SMTP server to the following:
<mail-session jndi-name="java:jboss/mail/Default"> <smtp-server ssl="true" outbound-socket-binding-ref="mail-smtp"> <login name="your_gmail_account" password="your_password"/> </smtp-server> </mail-session>
With this change we use SSL to login with the supplied username. To define the mail host where we login look for the following lines in the same file:
<outbound-socket-binding name="mail-smtp"> <remote-destination host="localhost" port="25"/> </outbound-socket-binding>
And modify this host to the following to use the GMail server:
<outbound-socket-binding name="mail-smtp"> <remote-destination host="smtp.gmail.com" port="465"/> </outbound-socket-binding>
That is it. Every JEE application deployed at this JBoss instance can now simply send mails by using the configured GMail account, which is available as JNDI resource with the key ‘java:jboss/mail/Default’.