How to debug emails in LF7?

Václav Suchánek, modified 6 Years ago. Junior Member Posts: 26 Join Date: 8/15/18 Recent Posts
Hello,

Is there an easy way how to trace/debug outcoming emails?

My scenario:
I am implementing in ServiceConfiguration.java custom email templates (custom.tmpl) for actions - article added and update.
My feature is ready to go, but i don't know how to debug these customized emails.

I have tried these methods:

1) To create 2 testing accounts (allowing them email notification in Account settings -> Alerts and Annoucements delivery)
     Results was: Only notifications were sent but no emails. Tested on default MessageBoards portlet and Wiki portlet.

2) Follow this blog: https://community.liferay.com/blogs/-/blogs/how-to-trace-mail-in-liferay-portal
    To set debug level in Server administration or in portal-log4j-ext.xml on email related categories.
    To set debug level in Server Administration -> Log Levels -> set debug level on com.liferay.mail.service.impl.MailServiceImpl and on all mail category related items.
    Result was: Only one line in tomcat console showed up:
    2019-03-13 10:34:16.033 DEBUG [liferay/subscription_sender-1][MailServiceImpl:257] sendEmail
    This line is nice, but i would like to know the email body.

Is there an another way or recomendation how to do it? Maybe use some extension/overrides for debugging MailServiceImpl methods? Or somehow work with an optional JavaMail properties in mail server administration?


My env:

liferay ce portal 7.1.2 ga3
tomcat 9.0.10
tested on localhost



Thanks in advance.

Vaclav
thumbnail
Fernando Fernandez, modified 6 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Hi Václav,

As a complement to debugging the emails inside the Liferay stack, I find a tool like FakeSMTP very useful. It's a fake server you can use on your dev machine and "trap" outgoing emails, allowing you to immediatly look at headers and message bodies.

HTH

Fernando
Jan Tošovský, modified 6 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
Seeing the code responsible for sending emails I am afraid that log level settings won't help here anymore:

https://github.com/liferay/liferay-portal/blob/0a5bb514913ee7e6f765926451900f8c7967fc48/portal-impl/src/com/liferay/mail/service/impl/MailServiceImpl.java#L260

After printing "sendEmail" message the task is forwarded to the MessageBus, where I am loosing the track what is done next.
thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Jan Tošovský

After printing "sendEmail" message the task is forwarded to the MessageBus, where I am loosing the track what is done next.
This might be the actual sender
Jan Tošovský, modified 6 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
So emails are sent using petra-mail module: https://github.com/liferay/liferay-portal/blob/master/modules/apps/petra/petra-mail/src/main/java/com/liferay/petra/mail/MailEngine.java

The logging is still available, but it cannot be activated directly from the Server Administration as it is not a core LR functionality any more. So the only way to enable debugging is to tweak log4j properties:

<logger name="com.liferay.petra.mail">
   <level value="DEBUG" />
</logger>

Tested, it works.

Btw, for testing you can generate emails via script. Go to the Script tab in the Server Administration and paste this Gist:
https://gist.github.com/jan-tosovsky-cz/56cd44d3216fb056d9b4259a997a9e86 

Jan
thumbnail
Scott McIntosh, modified 5 Years ago. New Member Posts: 9 Join Date: 3/26/10 Recent Posts
I know this is an old thread, but in case anyone comes looking I wanted to say that I had no problem setting com.liferay.petra.mail.MailEngine to DEBUG via the Server Administration.