Skip to content
Sven Kubiak edited this page Jul 27, 2018 · 3 revisions

mangoo I/O uses the mature Apache commons email to make sending eMails as easy as possible. If you want to send an eMail via mangoo I/O you need the Mail utility class. See for example:

Mail.newMail()
    .withRecipient("sansa.stark@winterfell.com")
    .withSubject("Lord of light")
    .withTemplate("emails/simple.ftl")
    .withContent("king", "geofrey")
    .send();

By convention mangoo I/O will lookup email templates in the “/templates” folder. From there you can use subfolder as you wish - see in the above example. If you don’t want to use the message body from a rendered template, you can also pass your custom body with the withBody(...) method.

Please note, that variables like Session, Flash, etc. which are automatically availabie in the normal template mechanism, are not available when sending emails. You have to pass them via the withContent method.

Default encoding for mail content is UTF-8.

Configuring the SMTP connection

Check the default values for the SMTP server on how to configure your SMTP server connection correctly.

Mocked SMTP server

For testing and development purposes, mangoo I/O provides a simple mocked SMTP server which is based on GreenMail.

Simply inject the SMTP server

@Inject
private Smtp smtp;

And start anywhere you want

smtp.start();

A good practice would be to use the lifecycle for this purpose.

The mocked SMTP server uses the configuration within application.yaml for host and port of the SMTP server and the start method only has an affect in dev and test mode. The mocked SMTP will not start in prod mode.