Skip to content

lettr-com/lettr-java

Repository files navigation

Lettr Java SDK

The official Java SDK for the Lettr Email API. A typed, builder-based client for emails, templates, domains, webhooks, audience, and campaigns — methods throw checked exceptions on failure.

Installation

Gradle

implementation 'com.lettr:lettr-java:1.4.0'

Maven

<dependency>
    <groupId>com.lettr</groupId>
    <artifactId>lettr-java</artifactId>
    <version>1.4.0</version>
</dependency>

Requirements

  • Java 11+

Quick Start

import com.lettr.Lettr;
import com.lettr.services.emails.model.*;

Lettr lettr = new Lettr("your-api-key");

CreateEmailOptions params = CreateEmailOptions.builder()
    .from("sender@example.com")
    .to("recipient@example.com")
    .subject("Hello from Lettr!")
    .html("<p>Hello, world!</p>")
    .build();

CreateEmailResponse response = lettr.emails().send(params);
System.out.println("Request ID: " + response.getRequestId());

Every builder validates required fields in build(), and setters are annotated with @Nonnull/@Nullable so your IDE surfaces what's required as you type.

Error Handling

Methods throw LettrException subclasses — catch the specific type you care about:

try {
    lettr.emails().send(params);
} catch (LettrValidationException e) {     // 422 — field-level details in e.getErrors()
    System.err.println(e.getMessage());
} catch (LettrApiException e) {            // other API errors — e.getStatusCode(), e.getErrorCode()
    System.err.println(e.getErrorCode());
} catch (LettrException e) {               // network / parsing errors
    System.err.println(e.getMessage());
}

See Error Handling for the full exception hierarchy and error codes.

Documentation

Full guides for every service, with complete request/response details, live in the docs:

📚 docs.lettr.com/quickstart/java

Topic Guide
Install, setup, sending Quickstart
Batch sending, Spring Boot, error handling Advanced
Manage Lettr templates & merge tags Templates
Add, verify, and manage sending domains Domains
Webhook endpoints for delivery & engagement events Webhooks
Lists, contacts, topics, properties, segments Audience
List, send, and schedule campaigns Campaigns
Endpoint reference (params & schemas) API Reference

License

MIT