Skip to content

Getting Started

email-template-builder lets you compose transactional emails fluently in Java. One build() call returns both a fully inlined, responsive HTML version and a matching plain-text version.

  • Java 11 or newer
  • The only runtime dependency is the Pebble template engine
<dependency>
<groupId>io.rocketbase.mail</groupId>
<artifactId>email-template-builder</artifactId>
<version>2.7.0</version>
</dependency>
import io.rocketbase.mail.EmailTemplateBuilder;
import io.rocketbase.mail.model.HtmlTextEmail;
HtmlTextEmail email = EmailTemplateBuilder.builder()
.header().text("Product Name").and()
.text("Welcome, Marie!").h1().center().and()
.text("Thanks for signing up. Confirm your email address to get started:").and()
.button("Confirm email", "https://example.com/confirm").blue().and()
.copyright("rocketbase").url("https://www.rocketbase.io").and()
.build();
String html = email.getHtml(); // styled, inlined HTML version
String text = email.getText(); // plain-text version

The plain-text version is derived automatically from the same content:

***************************
Product Name
***************************
Welcome, Marie!
Thanks for signing up. Confirm your email address to get started:
Confirm email -> https://example.com/confirm
-----------
©2026 rocketbase -> https://www.rocketbase.io

HtmlTextEmail is sender-agnostic — pass both versions to whatever mail infrastructure you use.

MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message,
MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
StandardCharsets.UTF_8.name());
helper.setTo(to);
helper.setSubject(subject);
helper.setText(email.getText(), email.getHtml());
helper.setFrom(from);
emailSender.send(message);

For sending we can recommend spring-boot-starter-mail, Simple Java Mail or our own postmark-spring integration.

A local SMTP catch-all like smtp4dev is handy to preview your emails during development:

Terminal window
docker run --rm -it -p 5555:80 -p 2525:25 rnwood/smtp4dev

Point your sender at localhost:2525 and browse the received mails at http://localhost:5555.