Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How to debug emails in LF7?
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
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
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
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
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.
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.
Jan TošovskýThis might be the actual sender
After printing "sendEmail" message the task is forwarded to the MessageBus, where I am loosing the track what is done next.
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:
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
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
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.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™