rocketbase.io email template builder

let this service generate your custom html/text emails

License

License

GroupId

GroupId

io.rocketbase.commons
ArtifactId

ArtifactId

email-template-builder
Last Version

Last Version

1.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

rocketbase.io email template builder
let this service generate your custom html/text emails
Project URL

Project URL

https://github.com/rocketbase-io/email-template-builder/
Source Code Management

Source Code Management

https://github.com/rocketbase-io/email-template-builder/tree/master/

Download email-template-builder

How to add to project

<!-- https://jarcasting.com/artifacts/io.rocketbase.commons/email-template-builder/ -->
<dependency>
    <groupId>io.rocketbase.commons</groupId>
    <artifactId>email-template-builder</artifactId>
    <version>1.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.rocketbase.commons/email-template-builder/
implementation 'io.rocketbase.commons:email-template-builder:1.6.0'
// https://jarcasting.com/artifacts/io.rocketbase.commons/email-template-builder/
implementation ("io.rocketbase.commons:email-template-builder:1.6.0")
'io.rocketbase.commons:email-template-builder:jar:1.6.0'
<dependency org="io.rocketbase.commons" name="email-template-builder" rev="1.6.0">
  <artifact name="email-template-builder" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.rocketbase.commons', module='email-template-builder', version='1.6.0')
)
libraryDependencies += "io.rocketbase.commons" % "email-template-builder" % "1.6.0"
[io.rocketbase.commons/email-template-builder "1.6.0"]

Dependencies

compile (3)

Group / Artifact Type Version
io.pebbletemplates : pebble jar 3.1.2
org.jsoup : jsoup jar 1.12.2
io.rocketbase.commons : colors jar 0.5.0

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.10

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

email-template-builder

logo

Build Status Maven Central

Let this service build your html/text emails in a fluent manner. It doesn't try to reinvent the wheel - it simply extends the given email-template of postmark and backed it for java to use it for many purposes.

You can write your email content fluently and the template builder cares for the correct instyling, conversation to txt version etc...

For sending the email I can recommend the spring-boot-starter-mail, simplejavamail or my postmark-spring...

release notes

  • 1.x bases mailgun templates

    • extra dependency on jsoup for auto inlining/transpiling to text
    • doc for old api could be found in wiki
  • 2.x bases on new postmark templates

    • pom artifact group changed to io.rocketbase.mail
    • removed jsoup from dependency and changed api in many cases
    • cleaned up a lot of code
    • separated module in two pices
      • common builder
      • markdown (with markdown support)

features

  • generate html and text mail via one fluent build
  • just pebble-template engine as dependency
  • support for the following content-types
    • Logo in the header
    • Text also with HTML support and Alignment configuration
    • Image with Alignment configuration and Link options
    • Button with custom Styling
    • Footer with HTML support and Alignment configuration
    • Copyright with dynamic Year and Link options
    • table with header, item/price, total
    • key value pairs
    • interface for tables to provide custom layouts
    • extra module to transpile markdown

usage

sample html/text

// generate html/text content
HtmlTextEmail htmlTextEmail = builder
        .header()
        .logo("https://www.rocketbase.io/img/logo-dark.png").logoHeight(41)
        .and()
        .text("Welcome, {{name}}!").h1().center().and()
        .text("Thanks for trying [Product Name]. We’re thrilled to have you on board. To get the most out of [Product Name], do this primary next step:").and()
        .button("Do this Next", "http://localhost").blue().and()
        .text("For reference, here's your login information:").and()
        .attribute()
        .keyValue("Login Page", "{{login_url}}")
        .keyValue("Username", "{{username}}")
        .and()
        .html("If you have any questions, feel free to <a href=\"mailto:{{support_email}}\">email our customer success team</a>. (We're lightning quick at replying.) We also offer <a href=\"{{live_chat_url}}\">live chat</a> during business hours.",
                "If you have any questions, feel free to email our customer success team\n" +
                        "(We're lightning quick at replying.) We also offer live chat during business hours.").and()
        .text("Cheers,\n" +
                "The [Product Name] Team").and()
        .copyright("rocketbase").url("https://www.rocketbase.io").suffix(". All rights reserved.").and()
        .footerText("[Company Name, LLC]\n" +
                "1234 Street Rd.\n" +
                "Suite 1234").and()
        .footerImage("https://cdn.rocketbase.io/assets/loading/no-image.jpg").width(100).linkUrl("https://www.rocketbase.io").and()
        .build();

// sent email
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(htmlTextEmail.getText(), htmlTextEmail.getHtml());
helper.setFrom(from);
emailSender.send(message);

preview HTML-Version

sample

preview Text-Version

Welcome, {{name}}!

Thanks for trying [Product Name]. We=E2=80=99re thrilled to have you on boa=
rd. To get the most out of [Product Name], do this primary next step:

Do this Next -> http://localhost

For reference, here's your login information:

Login Page: {{login_url}}
Username: {{username}}


If you have any questions, feel free to email our customer success team
(We're lightning quick at replying.) We also offer live chat during business hours.

Cheers,
The [Product Name] Team

sample table

TbConfiguration config = TbConfiguration.newInstance();
config.getContent().setFull(true);

HtmlTextEmail htmlTextEmail = builder
        .configuration(config)
        .header().text(header).and()
        .text("Hi {{name}},").and()
        .text("Thanks for using [Product Name]. This is an invoice for your recent purchase").and()
        .tableSimple("#.## '€'")
        .headerRow("Description", "Amount")
        .itemRow("Special Product\n" +
                "Some extra explanations in separate line", BigDecimal.valueOf(1333, 2))
        .itemRow("Short service", BigDecimal.valueOf(103, 1))
        .footerRow("Total", BigDecimal.valueOf(2363, 2))
        .and()
        .button("Download PDF", "http://localhost").gray().right().and()
        .text("If you have any questions about this receipt, simply reply to this email or reach out to our support team for help.").and()
        .copyright("rocketbase").url("https://www.rocketbase.io").suffix(". All rights reserved.").and()
        .footerText("[Company Name, LLC]\n" +
                "1234 Street Rd.\n" +
                "Suite 1234").and()
        .build();

preview HTML-Version

sample-table

sample table with image

TbConfiguration config = TbConfiguration.newInstance();
config.getContent().setWidth(800);

HtmlTextEmail htmlTextEmail = builder
        .configuration(config)
        .header().text(header).and()
        .text("Hi {{name}},").and()
        .text("Thanks for using [Product Name]. This is an invoice for your recent purchase").and()
        .tableSimpleWithImage("#.## '€'")
        .headerRow("Preview", "Description", "Amount")
        .itemRow("https://cdn.shopify.com/s/files/1/0255/1211/6260/products/TCW1142-07052_small.jpg?v=1589200198", "Damen Harbour Tanktop × 1\n" +
                "QUARTZ PINK / S", BigDecimal.valueOf(4995, 2))
        .itemRow("https://cdn.shopify.com/s/files/1/0255/1211/6260/products/TCM1886-0718_201_fdf0be52-639f-4ea8-9143-6bd75e0821b1_small.jpg?v=1583509609", "Herren ten Classic T-Shirt\n"+
                "FOREST GREEN HEATHER / XL", BigDecimal.valueOf(3995, 2))
        .itemRow("https://cdn.shopify.com/s/files/1/0255/1211/6260/products/TCM1939-0439_1332_da6f3e7c-e18d-4778-be97-c6c0b482b643_small.jpg?v=1583509671", "Herren Joshua Hanfshorts\n" +
                "DARK OCEAN BLUE / XL", BigDecimal.valueOf(6995, 2))
        .footerRow("Sum", BigDecimal.valueOf(15985, 2))
        .footerRow("Code - PLANT5", BigDecimal.valueOf(-799, 2))
        .footerRow("Total incl. Tax\n", BigDecimal.valueOf(15186, 2))
        .and()
        .button("Download PDF", "http://localhost").gray().right().and()
        .text("If you have any questions about this receipt, simply reply to this email or reach out to our support team for help.").and()
        .copyright("rocketbase").url("https://www.rocketbase.io").suffix(". All rights reserved.").and()
        .footerText("[Company Name, LLC]\n" +
                "1234 Street Rd.\n" +
                "Suite 1234").and()
        .build();

preview HTML-Version

sample-table

A custom table example could be found in wiki.

io.rocketbase.commons

rocketbase.io software productions GmbH

We are a bunch of passionate developers with a major in Java and Web Technologies.

Versions

Version
1.6.0
1.5.0
1.4.0
1.3.0
1.2.0
1.1.0
1.0.2
1.0.1
1.0.0
0.1.0