Blogs

Blogs

How to trace mail in Liferay Portal

Overview

Sometimes ... things do not go to plan when using mail (email) in Liferay Portal.

However you can quickly find the cause by logging the outbound mail message.

You can enable additional logging to help trace inbound and outbound mail.

NOTE: This article was extracted from article How to configure Google Mail in Liferay Portal

Test Environments

The following 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

Liferay Portal Mail Logging Configuration

Enable ALL (TRACE) Log Levels

Enable logging via Control Panel or Log4j configuration file.

See below for Control Panel configuration.

See appendix for sample Log4j configuration file.

Enable ALL (TRACE) Log Levels (Liferay Portal 6.0 and 6.1)

Enable logging level ALL (TRACE) for one or more of the following categories using "Control Panel > Server Administration > Log Levels"

  • com.liferay.mail.messaging
  • com.liferay.mail.service
  • com.liferay.mail.service.impl
  • com.liferay.mail.service.impl.MailServiceImpl
  • com.liferay.mail.messaging
  • com.liferay.portal.util.SubscriptionSender
  • com.liferay.portlet.announcements.messaging.CheckEntryMessageListener
  • com.liferay.portlet.announcements.service
  • com.liferay.portlet.announcements.service.impl.AnnouncementsEntryLocalServiceImpl
  • com.liferay.portlet.mail
  • com.liferay.util.mail
  • com.liferay.util.mail.MailEngine

Enable ALL (TRACE) Log Levels (Liferay Portal 6.2)

Enable logging level ALL (TRACE) for one or more of the following categories using "Dockbar > Admin > Control Panel > Server Administration > Log Levels"

  • com.liferay.mail.messaging
  • com.liferay.mail.messaging.MailMessageListener
  • com.liferay.mail.service
  • com.liferay.mail.service.impl
  • com.liferay.mail.service.impl.MailServiceImpl
  • com.liferay.mail.messaging
  • com.liferay.portal.kernel.messaging
  • com.liferay.portal.kernel.messaging.DefaultMessageBus
  • com.liferay.portal.kernel.messaging.config.AbstractMessagingConfigurator
  • com.liferay.portal.kernel.messaging.proxy.ProxyMessageListener
  • com.liferay.portal.util.SubscriptionSender
  • com.liferay.portlet.announcements.messaging.CheckEntryMessageListener
  • com.liferay.portlet.announcements.service
  • com.liferay.portlet.announcements.service.impl.AnnouncementsEntryLocalServiceImpl
  • com.liferay.util.mail
  • com.liferay.util.mail.MailEngine
  • com.liferay.webform.portlet.WebFormPortlet

JavaMail Session Logging Configuration

The JavaMail API supporta a "debug" mode in which mail messages are logged to standard output (stdout).

This can be useful when tracing message headers and/or content.

To enable the JavaMail debug mode, configure the DEBUG (or ALL) logging level for either of these logging (categoriy) entries :

  • com.liferay.util.mail
  • com.liferay.util.MailEngine

This loggig configuration is equivalent to the following JavaMail API code:

java.util.Properties properties = ...
javax.mail.Session session = Session.getInstance(properties);
session.setDebug(true);

For the curious, the Liferay Portal 6.2 mail debug logic in class com.liferay.util.MailEngine.

References

Appendix - Sample Log4j Configuration File

FILE: TOMCAT/lib/ext/META-INF/portal-log4j-ext.xml

NOTE: Adapt the following sample porta log4j configuration file to suit your testing requirements.

NOTE: Change the timezone definition from {Australia/Perth} to your local timezone, or remove entry to default to GMT/UTC.

e.g.

<?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" WARN="true" debug="true">

        <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
                <layout class="org.apache.log4j.EnhancedPatternLayout">
                        <param name="ConversionPattern" value="%d{ISO8601}{Australia/Perth} %-5p [%t][%c{1}:%L] %m%n" />
                </layout>
        </appender>

        <appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender">
                <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
                        <param name="FileNamePattern" value="@liferay.home@/logs/liferay@spi.id@.%d{yyyy-MM-dd}.log" />
                </rollingPolicy>

                <layout class="org.apache.log4j.EnhancedPatternLayout">
                        <param name="ConversionPattern" value="%d{ISO8601}{Australia/Perth} %-5p [%t][%c{1}:%L] %m%n" />
                </layout>
        </appender>
        
        <category name="com.liferay.mail.messaging">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.mail.service">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.mail.service.impl">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.mail.service.impl.MailServiceImpl">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.portal.util.SubscriptionSender">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.portlet.mail">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.portlet.announcements.messaging.CheckEntryMessageListener">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.portlet.announcements.service">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.portlet.announcements.service.impl.AnnouncementsEntryLocalServiceImpl">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.util.mail">
                <priority value="ALL" />
        </category>

        <category name="com.liferay.util.mail.MailEngine">
                <priority value="ALL" />
        </category>

</log4j:configuration>