Send transactional emails from Java with the official Lettr SDK, featuring type-safe builders and Java 11+ support.
Send transactional emails from your Java applications using the official Lettr Java SDK. The SDK provides a type-safe, builder-pattern interface for the Lettr API with comprehensive error handling and Java 11+ support.The lettr-java package gives you an idiomatic Java client that works with any Java application — Spring Boot, Jakarta EE, Android, or standalone applications. It follows Java conventions and integrates seamlessly with your existing codebase.Using Cursor? Jump straight in using this prompt
public class Main { public static void main(String[] args) { String apiKey = System.getenv("LETTR_API_KEY"); if (apiKey == null || apiKey.isEmpty()) { throw new IllegalStateException("LETTR_API_KEY environment variable is required"); } Lettr lettr = new Lettr(apiKey); }}
CreateEmailOptions email = CreateEmailOptions.builder() .from("notifications@yourdomain.com") .to("user@example.com") .subject("Plain text email") .text("This is a plain text email.\n\nIt has no HTML formatting.") .build();lettr.emails().send(email);
Send both HTML and plain text versions for maximum compatibility:
CreateEmailOptions email = CreateEmailOptions.builder() .from("notifications@yourdomain.com") .to("user@example.com") .subject("Multipart email") .html("<h1>Hello!</h1><p>This is the HTML version.</p>") .text("Hello!\n\nThis is the plain text version.") .build();lettr.emails().send(email);
Providing both HTML and plain text ensures your emails are readable in all email clients, including text-only clients and accessibility tools.