https://github.com/ditschedev/mailo
This is a client for sending emails easily from a Spring Boot REST API. It makes use of Mustache for templating and is adaptable.
https://github.com/ditschedev/mailo
email java mail mjml mjml4j smtp template templates
Last synced: over 1 year ago
JSON representation
This is a client for sending emails easily from a Spring Boot REST API. It makes use of Mustache for templating and is adaptable.
- Host: GitHub
- URL: https://github.com/ditschedev/mailo
- Owner: ditschedev
- Created: 2020-11-30T11:26:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-11T15:03:38.000Z (over 1 year ago)
- Last Synced: 2025-04-12T23:13:53.548Z (over 1 year ago)
- Topics: email, java, mail, mjml, mjml4j, smtp, template, templates
- Language: Java
- Homepage:
- Size: 90.8 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mailo - Java Mail Library
This is a client for sending emails easily from java applications :heart:.
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:
```xml
dev.ditsche
mailo
1.1.4
```
## 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](mjml.io).
##### `MAILO_APP_SECRET`
Sets the MJML application secret obtained by requesting api keys from [mjml.io](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:
```java
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.
```java
// Create a smtp config for our mail provider
SmtpConfig config = new SmtpConfig();
config.setHost("smtp.example.com");
config.setPort(465);
config.setUsername("test@example.com");
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("sender@test.com", "Sender name"))
.to(new MailAddress("test@test.com", "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:
```java
// 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("sender@test.com", "Sender name"))
.to(new MailAddress("test@test.com", "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)