How to configure Google Mail in Liferay Portal

Overview

Configuring Liferay Portal to use Google Mail is relatively easy.

The key is to enable SSL socket connections.

The following article provides steps to enable Liferay Portal to send email via Google Mail.

To assist with tracing mail issue, please refer to related article How to trace mail in Liferay Portal.

Test Environments

The following mail configuration has been tested with these products:

  • Liferay Portal 6.0 EE
  • Liferay Portal 6.1 EE 
  • Liferay Portal 6.2 EE

The configuration may also be suitable for these products:

  • Liferay Portal 6.0 CE
  • Liferay Portal 6.1 CE
  • Liferay Portal 6.2 CE

Mail Configuration

Configure mail settings in Liferay Portal using one of these approaches :

  1. Portal properties
  2. Portal properties and JNDI
  3. Control Panel > Server Administration > Mail

Background - Secure Mail Configuration

Establishing an email session with the Google Mail service requires a secure connection.

The default Liferay Portal 6.x mail configuration properties do not show how to establish a secure connection using additional mail SSL properties.

The mail SMTP properties "mail.session.mail.smtp.socketFactory" and "mail.session.mail.smtp.starttls.enable" are not defined in the default portal properties file "portal-impl.jar!portal.properties".

For the curious, the secure (SSL) and TLS properties are defined at runtime by Liferay Portal class com.liferay.util.mail.MailEngine

Configure using Portal Properties

Add/update file "LIFERAY_HOME/portal-ext.properties" with the following mail session properties :

FILE: LIFERAY_HOME/portal-ext.properties

mail.session.mail.pop3.host=pop.gmail.com
mail.session.mail.pop3.password=PASSWORD
mail.session.mail.pop3.port=110
mail.session.mail.pop3.user=USER
mail.session.mail.imap.host=imap.gmail.com
mail.session.mail.imap.port=993
mail.session.mail.store.protocol=imap
mail.session.mail.transport.protocol=smtp
mail.session.mail.smtp.host=smtp.gmail.com
mail.session.mail.smtp.password=PASSWORD
mail.session.mail.smtp.user=USER
mail.session.mail.smtp.port=465
mail.session.mail.smtp.auth=true
mail.session.mail.smtp.starttls.enable=true
mail.session.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

NOTE: Replace USER and PASSWORD with required user and password for Google Mail account.

Configure using Portal Properties and JNDI

Configure Portal Properties

Add/update file "LIFERAY_HOME/portal-ext.properies" with the following mail session properties :

FILE: LIFERAY_HOME/portal-ext.properties

mail.session.jndi.name=mail/MailSession

Configure Tomcat Context

Add/update file "LIFERAY_HOME/tomcat-xxx/conf/Catalina/localhost/ROOT.xml" with the following "Resource" element :

<Resource
   name="mail/MailSession"
   auth="Container"
   type="javax.mail.Session"
   mail.imap.host="imap.gmail.com"
   mail.imap.port="993"
   mail.pop.host="pop.gmail.com"
   mail.store.protocol="imap"
   mail.transport.protocol="smtp"
   mail.smtp.host="smtp.gmail.com"
   mail.smtp.port="465"
   mail.smtp.auth="true"
   mail.smtp.starttls.enable="true"
   mail.smtp.user=USER
   password=PASSWORD
   mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
/>

NOTE: Replace USER and PASSWORD with required user and password for Google Mail account.

Configure using Control Panel > Server Administration > Mail

Sign in to Liferay Portal as admin user.

Navigate to "Control Panel > Server Administration > Mail"

Edit POP and SMTP mail settings.

eg.

Incoming POP Settings

  • Incomding POP Server:  pop.gmail.com
  • Incoming Port:  110
  • Use a Secure Network Connection:  YES
  • User Name:  POP-EMAIL-USER
  • Password:  POP-EMAIL-PASSWORD

Outgoing SMTP Server Settings

  • Outgoing SMTP Server:  smtp.gmail.com
  • Outgoing Port:  465
  • Use a Secure Network Connection:  YES
  • User Name:  SMTP-EMAIL-USER
  • Password:  SMTP-EMAIL-PASSWORD

Troubleshooting

The contents of this section have moved to article How to trace mail in Liferay Portal

References