Java client for the MJML email builder API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
mjml4j-client
.gitignore
LICENSE
README.MD
build.gradle
gradlew.bat
settings.gradle

README.MD

MJML4j

A MJML API client for Java.

You can use this library to communicate with the MJML REST Api and convert your pre-built MJML to a HTML email.

Support

This library currently supports V1 of the MJML API

Basic Use

Dependency
  • Gradle: In your build.gradle add the following:
repositories {
    mavenCentral()

    maven {
        url "http://nexus.fusing-ideas.com/content/groups/public/"
    }
}

dependencies {
    compile 'ifusion:mjml-client:0.1.2'
}
  • Maven: in your pom.xml add the following repository and dependency nodes
<project>
   <repositories>
       <repository>
         <id>mjml-client-repo</id>
         <url>http://nexus-ed0906.rhcloud.com/nexus/content/groups/public/</url>
       </repository>
   </repositories>
   <dependencies>
       <dependency>
           <groupId>ifusion</groupId>
           <artifactId>mjml-client</artifactId>
           <version>0.1.2</version>
       </dependency>
   </dependencies>
</project>
Create a client
MJMLClient client = MJMLClient.newDefaultClient()
                              .withApplicationID("...")
                              .withAPIKey("...");

You can get an ApplicationID and APIKey from https://mjml.io/api

Render some MJML
  • Build a RenderRequest and call the client
    RenderRequest request = new RenderRequest("<mjml>...<mjml>");
    RenderResponse response = client.render(request);
    String mjml = response.getMJML();
  • Handling API errors
   RenderRequest request = new RenderRequest("<mjml>...<mjml>");
   try {
       RenderResponse response = client.render(request);
       String mjml = response.getMJML();
   } catch (MJMLClientErrorException c) {
       // Do something
       // For example
       // log.warn("Render error: " + c.getMessage() + ", request-id: " + c.getRequestId());
   } catch (MJMLServerErrorException s) {
       // Do something
       // For example
       // log.warn("Render error: " + s.getMessage() + ", request-id: " + s.getRequestId());
   } catch (MJMLException e) {
       // Do something
       // For example
       // log.warn("Render error: " + s.getMessage());
   }

Building MJML Dynamically

This library currently only supports the conversion of a pre-built MJML document to HTML. MJML document building is a work in progress but for now you can use libraries such as Jdom2/Jsoup to build your MJML Document Object Model. You can then use this library to convert it to a HTML email.