Quick Send Methods
For simple emails, use the shorthand methods. These are convenience wrappers around the email builder that handle the most common use cases with minimal code.HTML Email
sendHtml() method is perfect for simple HTML emails where you don’t need advanced features like tracking configuration or metadata.
Plain Text Email
from parameter accepts either a string email address or an EmailAddress value object to set a display name. The to parameter accepts a single email string or an array of recipients (maximum 50).
You can send both HTML and plain text in the same email by using the email builder with both
->html() and ->text() methods. Mail clients that don’t support HTML will display the plain text version.Template Email
substitutionData array keys correspond to merge tags in your Lettr template (e.g., {{name}}). See Merge Tags & Template Language for the full syntax including conditionals and loops.
For more advanced template usage including versioning, see the Templates page.
Email Builder
For complex emails that require multiple features, use the fluent email builder. This gives you access to every option the Lettr API supports in a chainable interface:Templates with Substitution Data
Send using a Lettr template with dynamic data:useTemplate() method accepts an optional version parameter to pin a specific template version. See Templates for details.
When to use versioning:
- Production safety — Pin to a known-good version so publishing a new draft doesn’t affect live emails
- A/B testing — Send different versions to different cohorts and compare metrics
- Gradual rollout — Test a new version with a subset of users before publishing
Attachments
Add attachments from file paths or binary data:- Base64-encodes the file content
- Detects the MIME type if not provided
- Validates file size and format
Email Options
Fine-tune email behavior with tracking and processing options:Click and open tracking are enabled by default. For transactional emails like password resets or order confirmations, leave tracking enabled — the data helps you diagnose delivery issues. For privacy-sensitive communications, disable tracking explicitly.
Handling Responses
Every send method returns aSendEmailResponse with details about the request:
requestId is a unique identifier for this email transmission. Store it in your database to correlate emails with delivery events later. You can use it to query the Lettr API for detailed delivery information including opens, clicks, bounces, and complaints.
Error Handling
The SDK throws typed exceptions for different API errors, making it easy to handle specific failure cases:What’s Next
Templates
Manage and send Lettr templates with versioning
Email Tracking
Track opens, clicks, and engagement
Metadata
Attach custom data to emails for analytics
Error Handling
Understand errors and retry strategies