Email API Integration Guide with Java

Minimum code that you need to integrate Mailazy with your Java application


You need to complete these given prerequisites, you can skip the step if you have already completed.

  1. Sign up for a Mailazy account.
  2. Complete Domain Authentication.
  3. Generate the Mailazy Access Key

Integrate Mailazy with Java

Start Sending mail using the code provided below:


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Main {

    public static void main(String[] args) throws JSONException {

        JSONObject json = new JSONObject();
        json.put("to", new JSONArray().put(""));
        json.put("from", "");
        json.put("subject", "<SUBJECT>");

        JSONArray content = new JSONArray();
        content.put(new JSONObject().put("type", "text/plain").put("value", "hello world!"));
        content.put(new JSONObject().put("type", "text/html").put("value", "<b>hello world!</b>"));

        json.put("content", content);

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .header("Content-Type", "application/json")
                .header("X-Api-Key", "<API-KEY>")
                .header("X-Api-Secret", "<API-SECRET>")

        client.sendAsync(request, HttpResponse.BodyHandlers.ofString())