Why Lettr Works Well with Serverless
Serverless functions are stateless and short-lived, which makes SMTP connections impractical. Lettr’s HTTP API is ideal for serverless environments because:- No connection pooling — Each request is independent, no persistent SMTP connections needed
- Fast cold starts — A single HTTP call is all it takes to send an email
- Built-in retries — Lettr handles delivery retries, so your function doesn’t need to
- Async by design — Fire-and-forget sending keeps function execution time short
- No state management — Send emails without databases or queues
Unlike SMTP, which requires maintaining a persistent TCP connection, HTTP requests are stateless and complete in milliseconds — perfect for serverless architectures where functions can be cold-started at any time.
Prerequisites
Before you begin, make sure you have:API Key
Create an API key in the Lettr dashboard
Verified Domain
Add and verify your sending domain
Choose Your Platform
AWS Lambda
Send emails from AWS Lambda functions
Vercel Functions
Integrate with Vercel serverless functions
Cloudflare Workers
Send emails from Cloudflare Workers
Generic Example
On any serverless platform, sending an email is a single HTTP POST request:Complete Example with Error Handling
Here’s a production-ready example with error handling, logging, and retry logic:Using with Lettr SDK
If your platform supports npm packages, you can use the Lettr Node.js SDK for a cleaner interface:Environment Variables
All serverless platforms support environment variables. Set these for your function:- AWS Lambda: Use AWS Secrets Manager or Lambda environment variables
- Vercel: Add via dashboard or
vercel env add - Cloudflare Workers: Use
wrangler secret put
Best Practices for Serverless Email
1. Set Appropriate Timeouts
Ensure your function timeout is long enough for the HTTP request:2. Handle Cold Starts
The first request to a cold function may be slower. Use a lightweight HTTP client to minimize initialization time:3. Implement Idempotency
Use theidempotency_key parameter to prevent duplicate sends on retries:
4. Monitor Function Execution
Log request IDs for debugging:5. Keep Functions Lightweight
Avoid large dependencies. Use the platform’s nativefetch API instead of libraries like axios:
Common Serverless Architectures
Event-Triggered Emails
Send emails in response to events (user signup, purchase, etc.):Scheduled Emails
Use platform-specific schedulers (CloudWatch Events, Vercel Cron, etc.):Batch Processing
Process multiple emails in a single function invocation:For sending to many recipients (100+), consider using batch sending with a single API call or processing in smaller chunks to avoid function timeouts.
What’s Next
AWS Lambda
Deploy on AWS Lambda
Vercel Functions
Deploy on Vercel
Cloudflare Workers
Deploy on Cloudflare
API Reference
Complete API documentation