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.
Requirements
Section titled “Requirements”- Java 11 or newer
- The only runtime dependency is the Pebble template engine
Installation
Section titled “Installation”<dependency> <groupId>io.rocketbase.mail</groupId> <artifactId>email-template-builder</artifactId> <version>2.7.0</version></dependency>implementation("io.rocketbase.mail:email-template-builder:2.7.0")Your first email
Section titled “Your first email”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 versionString text = email.getText(); // plain-text versionThe 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.ioSending the email
Section titled “Sending the email”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);Email mail = EmailBuilder.startingBlank() .to(to) .from(from) .withSubject(subject) .withHTMLText(email.getHtml()) .withPlainText(email.getText()) .buildEmail();mailer.sendMail(mail);For sending we can recommend spring-boot-starter-mail, Simple Java Mail or our own postmark-spring integration.
Testing locally
Section titled “Testing locally”A local SMTP catch-all like smtp4dev is handy to preview your emails during development:
docker run --rm -it -p 5555:80 -p 2525:25 rnwood/smtp4devPoint your sender at localhost:2525 and browse the received mails at http://localhost:5555.
Next steps
Section titled “Next steps”- Explore all content blocks in the Builder API
- Adjust colors, widths and layout via Configuration
- See complete, rendered Examples