I’ve recently been needing to test emails with Moqui, and I came across a good solution. Moqui has a 3rd cousin twice removed framework called JHipster. I found this post by them about setting up a local SMTP server.
I’ve always thought setting up a local SMTP server would be too much of a pain for testing, but this was incredibly easy, and I thought I would share it.
All you need to do is add this to a demo data file and load it:
<!-- To get this working run docker run -p 1080:1080 -p 1025:1025 soulteary/maildev and go to http://localhost:1080 -->
<moqui.basic.email.EmailServer emailServerId="SYSTEM" smtpHost="localhost" smtpPort="1025"/>
<!-- Create a fromAddress for any email that you want to test -->
<moqui.basic.email.EmailTemplate emailTemplateId="PASSWORD_RESET" fromAddress="test@localhost"/>
Then run this on your local machine
docker run -p 1080:1080 -p 1025:1025 maildev/maildev
Another option is the embedded SMTP server: org.subethamail:subethasmtp is the maven ID.
It is enabled using a Moqui Conf XML file with a ToolFactory class, here is the OOTB setting in MoquiDefaultConf.xml, disabled by default:
<!-- SubEtha SMTP ToolFactory starts an SMTP server using the MOQUI_LOCAL EmailServer settings, emails received trigger EMECA rules -->
<tool-factory class="org.moqui.impl.tools.SubEthaSmtpToolFactory" init-priority="50" disabled="true"/>
This doesn’t do exactly what another SMTP server does, ie it won’t forward outgoing email, but it will receive email and trigger EMECA rules which can be used to process incoming email messages, or just log them for testing.
The eventual idea with this is to handle automation of incoming email, like adding comments to a WorkEffort or other CommunicationEvent sorts of things by replying to notification emails, or even managing incoming messages associated with transactional records like orders, invoices, etc along with a queue if needed for a human to look at it… or in general whatever you might imagine for handling incoming emails, and without having to poll a POP or IMAP account on another SMTP server.