Mailo - Java Mail Library

This is a client for sending emails from a Spring Boot REST API. It makes use of Mustache for templating, mjml is supported by default and it's adaptable.

License

License

GroupId

GroupId

dev.ditsche
ArtifactId

ArtifactId

mailo
Last Version

Last Version

1.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

Mailo - Java Mail Library
This is a client for sending emails from a Spring Boot REST API. It makes use of Mustache for templating, mjml is supported by default and it's adaptable.
Project URL

Project URL

https://github.com/ditschedev/mailo
Source Code Management

Source Code Management

https://github.com/ditschedev/mailo

Download mailo

How to add to project

<!-- https://jarcasting.com/artifacts/dev.ditsche/mailo/ -->
<dependency>
    <groupId>dev.ditsche</groupId>
    <artifactId>mailo</artifactId>
    <version>1.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/dev.ditsche/mailo/
implementation 'dev.ditsche:mailo:1.1.3'
// https://jarcasting.com/artifacts/dev.ditsche/mailo/
implementation ("dev.ditsche:mailo:1.1.3")
'dev.ditsche:mailo:jar:1.1.3'
<dependency org="dev.ditsche" name="mailo" rev="1.1.3">
  <artifact name="mailo" type="jar" />
</dependency>
@Grapes(
@Grab(group='dev.ditsche', module='mailo', version='1.1.3')
)
libraryDependencies += "dev.ditsche" % "mailo" % "1.1.3"
[dev.ditsche/mailo "1.1.3"]

Dependencies

compile (7)

Group / Artifact Type Version
com.sun.mail : javax.mail jar 1.6.2
org.projectlombok : lombok jar 1.18.12
com.sendinblue : sib-api-v3-sdk jar 4.1.1
com.wildbit.java : postmark jar 1.5.3
com.sendgrid : sendgrid-java jar 4.6.4
com.github.spullara.mustache.java : compiler jar 0.9.6
org.apache.httpcomponents : httpclient jar 4.5.10

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.6.2
org.assertj : assertj-core jar 3.16.1

Project Modules

There are no modules declared in this project.

Mailo - Java Mail Library

This is a client for sending emails easily from java applications ❤️ .

It is extendable, as you can add custom mail providers and comes with a SMTP and some mail service providers out of the box.

Installation

Add the dependency to your maven dependencies:

<dependency>
    <groupId>dev.ditsche</groupId>
    <artifactId>mailo</artifactId>
    <version>1.1.3</version>
</dependency>

Configuration

Environment Variables

Configuration is easy using the predefined environment variables. See below for more details:

MAILO_APP_ID

Sets the MJML application id obtained by requesting api keys from mjml.io.

MAILO_APP_SECRET

Sets the MJML application secret obtained by requesting api keys from mjml.io.

MAILO_TEMPLATE_DIR

Sets the root template directory in the classpath where all mail templates are located. Defaults to ./templates/.

Config Object

The libary is designed to be configured through environment variables, but you can use the config object too. Before sending or building mails, get the current config by using:

MailoConfig config = MailoConfig.get();

Now you can set the values as you need them to be programmatically.

Usage

Creating templates

Write your template with mjml and place them in your template directory inside of your Java Application. By default the library searches /templates/** in your classpath resources.

Sending mails

To send a mail using smtp, adapt the following code snippet.

// Create a smtp config for our mail provider
SmtpConfig config = new SmtpConfig();
config.setHost("smtp.example.com");
config.setPort(465);
config.setUsername("[email protected]");
config.setPassword("test123!");

// Create a mail provider
MailProvider mailProvider = new SmtpMailProvider(config);

// Build a mail
Mail mail = MailBuilder.mjml()
    .subject("Email Subject")
    .from(new MailAddress("[email protected]", "Sender name"))
    .to(new MailAddress("[email protected]", "Test Name"))
    .params("url", "http://example.com")
    .params("name", "John Doe")
    .template("path/to/template.mjml") // .mjml extension is optional
    .build();

// Send the mail
mailProvider.send(mail);

You can send mails using some big mail providers as well, if you don't like to use smtp directly. For example Postmark:

// Create a mail provider
MailProvider mailProvider = new PostmarkMailProvider("YOUR_POSTMARK_SERVER_TOKEN");

// Build a mail
Mail mail = MailBuilder.create()
    .subject("Email Subject")
    .from(new MailAddress("[email protected]", "Sender name"))
    .to(new MailAddress("[email protected]", "Test Name"))
    .params("url", "http://example.com")
    .params("name", "John Doe")
    .template("path/to/template.mjml")
    .build();

// Send the mail
mailProvider.send(mail);

Currently available are:

  • Postmark
  • SendGrid
  • Sendinblue
  • Mailgun (coming soon)
  • Mailjet (coming soon)

Versions

Version
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0