New to the Java SDK? Start with the Java Quickstart to learn the basics first.
Advanced Features
Multiple Recipients
Add multiple To, CC, and BCC recipients:BCC recipients are hidden from all other recipients. They receive the email but their addresses are not visible in the headers.
Reply-To Address
Specify a different reply-to address:Attachments
Add file attachments to your emails:Templates
Send emails using Lettr-managed templates:Custom Headers
Add custom email headers:Tracking
Enable open and click tracking:Open tracking works by embedding a transparent pixel image. Click tracking rewrites links to go through Lettr’s tracking domain. Both features respect user privacy and comply with email regulations.
Metadata
Attach custom metadata for tracking and filtering:Error Handling
The SDK provides structured exception types for different error scenarios:The Java SDK exposes three exception types:
LettrException (base), LettrApiException (any non-2xx response — branch on getStatusCode() and getErrorCode()), and LettrValidationException (422 with getErrors()).Common Error Scenarios
Unverified domain:- Exception:
LettrValidationException - Message: “The from address domain is not verified”
- Solution: Verify your domain in the dashboard
- Exception:
LettrApiExceptionwithgetStatusCode() == 401 - Message: “Invalid API key”
- Solution: Check your API key is correct and active
- Exception:
LettrApiExceptionwithgetStatusCode() == 429 - Message: “Too many requests”
- Solution: Implement exponential backoff retry logic
Batch Sending
Send multiple emails concurrently using CompletableFuture:With Concurrency Limiting
Use an ExecutorService to limit concurrent requests:Spring Boot Integration
Configuration
Configure the Lettr client as a Spring bean:Email Service
Create an email service that uses dependency injection:REST Controller
Use the email service in a REST controller:Best Practices
Use Environment Variables
Never hardcode API keys. Use environment variables or a configuration management system:Validate Before Sending
Validate email addresses before making API calls:Log Request IDs
Always log therequestId from successful sends for tracking and debugging:
Handle Errors Gracefully
Implement retry logic for transient errors:Reuse the Client
Create a single client instance and reuse it across requests:Troubleshooting
Unverified domain error
Unverified domain error
If you see “The from address domain is not verified”:
- Verify your domain in the Lettr dashboard
- Ensure the
fromaddress uses the verified domain - Wait for DNS propagation (can take up to 48 hours)
- See Domain Verification for help
Authentication failed (401 error)
Authentication failed (401 error)
If you see authentication errors:
- Check your API key is correct and starts with
lttr_ - Verify the key is 68 characters total (prefix + 64 hex chars)
- Ensure the key hasn’t been revoked in the dashboard
- Confirm you’re reading from the correct environment variable or config
Connection timeout
Connection timeout
If requests timeout:
- Increase the HTTP client timeout (default may be too short)
- Check your network connectivity and firewall settings
- Verify
app.lettr.comis reachable - Use a custom HttpClient with longer timeout settings
Dependency or build errors
Dependency or build errors
If you see Maven/Gradle errors:
- Run
mvn clean installorgradle clean buildto refresh dependencies - Check your Java version is 11 or later:
java -version - Verify the artifact ID is correct:
com.lettr:lettr-java - Clear your local Maven repository:
~/.m2/repository
Rate limit exceeded (429 error)
Rate limit exceeded (429 error)
If you’re hitting rate limits:
- Implement exponential backoff retry logic (see Best Practices)
- Use ExecutorService for controlled concurrent sending
- Consider upgrading your Lettr plan for higher limits
- Spread requests over time instead of bursts
Serialization or JSON errors
Serialization or JSON errors
If you encounter JSON parsing errors:
- Ensure all required builder fields are provided
- Check that email addresses are properly formatted
- Verify attachment content is properly base64-encoded
- Use proper character encoding (UTF-8) for email content
What’s Next
API Reference
Complete API documentation
Templates
Use Lettr-managed templates
Webhooks
Track delivery events
Best Practices
Email deliverability tips