Sendery
Sendery

Language SDKs

Java

Send published Sendery templates from Java.

Install
<dependency>
  <groupId>co.sendery</groupId>
  <artifactId>sendery-java</artifactId>
  <version>0.1.0</version>
</dependency>
Source code

Requirements

Java 17+.

Set up

Publish a welcome template with name and action_url variables, and create a project API key. Store it as SENDERY_API_KEY on your server.

Shell
export SENDERY_API_KEY="your_project_api_key"

Send an email

The response contains the accepted email’s id and status.

Java
import co.sendery.Sendery;
import java.util.Map;

public class SendWelcome {
    public static void main(String[] args) {
        var sendery = new Sendery(System.getenv("SENDERY_API_KEY"));
        var receipt = sendery.send("[email protected]", "welcome", Map.of(
            "name", "Alex",
            "action_url", "https://example.com/start"
        ));
        System.out.println(receipt.id());
    }
}

Retrieve an email

Use the returned ID to check delivery status. SendReceipt also provides errorCode(), createdAt(), and submittedAt(). Calls block until the request completes.

Java
var message = sendery.get(receipt.id());
System.out.println(message.status());

Retry a send

Use a key such as welcome-123 for one email, and keep the payload unchanged on retries. retry(3) allows up to three additional attempts for temporary failures; send() alone makes one attempt.

Java
var email = sendery.prepare("[email protected]", "welcome", Map.of(
    "name", "Alex", "action_url", "https://example.com/start"
), null, "welcome-123");
var receipt = email.retry(3).send();

Handle errors

Catch the SDK exception to inspect the status and code. Retry delays are in seconds. The example uses the prepared email from the retry example above.

Java
try {
    var receipt = email.retry(3).send();
    System.out.println(receipt.id());
} catch (co.sendery.SenderyException error) {
    System.err.println(error.status() + ": " + error.code());
    // error.errors() contains field-level validation errors.
    // error.retryAfter() is a delay in seconds, when provided.
    throw error;
}