mjml4j-client

'Java Client for the MJML API'

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

io.camassia
ArtifactId

ArtifactId

mjml4j-client
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

mjml4j-client
'Java Client for the MJML API'
Project URL

Project URL

https://github.com/ed0906/mjml4j
Source Code Management

Source Code Management

https://github.com/ed0906/mjml4j

Download mjml4j-client

How to add to project

<!-- https://jarcasting.com/artifacts/io.camassia/mjml4j-client/ -->
<dependency>
    <groupId>io.camassia</groupId>
    <artifactId>mjml4j-client</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.camassia/mjml4j-client/
implementation 'io.camassia:mjml4j-client:1.0.0'
// https://jarcasting.com/artifacts/io.camassia/mjml4j-client/
implementation ("io.camassia:mjml4j-client:1.0.0")
'io.camassia:mjml4j-client:jar:1.0.0'
<dependency org="io.camassia" name="mjml4j-client" rev="1.0.0">
  <artifact name="mjml4j-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.camassia', module='mjml4j-client', version='1.0.0')
)
libraryDependencies += "io.camassia" % "mjml4j-client" % "1.0.0"
[io.camassia/mjml4j-client "1.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar 2.8.8.1
org.apache.httpcomponents : httpclient jar 4.5.3
commons-io : commons-io jar 2.5

test (3)

Group / Artifact Type Version
junit : junit jar 4.11
org.assertj : assertj-core jar 3.8.0
com.github.tomakehurst : wiremock jar 2.6.0

Project Modules

There are no modules declared in this project.

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()
}

dependencies {
    compile 'io.camassia:mjml-client:1.0.0'
}
  • Maven: in your pom.xml add the following repository and dependency nodes
<project>
   <dependencies>
       <dependency>
           <groupId>io.camassia</groupId>
           <artifactId>mjml4j-client</artifactId>
           <version>1.0.0</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.

Versions

Version
1.0.0