Skip to main content
This guide covers advanced features of the Lettr Go SDK including attachments, templates, batch sending, error handling, and best practices for production applications.
New to the Go SDK? Start with the Go Quickstart to learn the basics first.

Advanced Features

CC and BCC Recipients

Add 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:
Attach multiple files:
Attachments must be base64-encoded. The total size of all attachments should not exceed 10MB. Larger files should be hosted and linked instead.

Templates

Send emails using Lettr-managed templates:
Templates are managed in the Lettr dashboard. Use merge tags to personalize content without rebuilding HTML in your code.

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:
Metadata is returned in webhook events and can be used to correlate emails with your application data.

Error Handling

The SDK provides structured error responses for different error scenarios:

Common Error Scenarios

Unverified domain:
  • Error: 422 Validation Error
  • Message: “The from address domain is not verified”
  • Solution: Verify your domain in the dashboard
Invalid API key:
  • Error: 401 Authentication Error
  • Message: “Invalid API key”
  • Solution: Check your API key is correct and active
Rate limit exceeded:
  • Error: 429 Rate Limit Error
  • Message: “Too many requests”
  • Solution: Implement exponential backoff retry logic

Batch Sending

Send multiple emails efficiently using goroutines:

With Rate Limiting

Use a semaphore to limit concurrent requests:
For large batches, consider using a worker pool pattern or a job queue to manage concurrent requests and handle failures gracefully.

Context and Timeouts

All SDK methods accept context.Context for cancellation and timeouts:

Cancellation

Cancel requests when they’re no longer needed:

Best Practices

Use Environment Variables

Never hardcode API keys. Use environment variables or a secrets manager:

Validate Before Sending

Validate email addresses before making API calls to avoid unnecessary errors:

Log Request IDs

Always log the RequestID from successful sends for tracking and debugging:

Handle Errors Gracefully

Implement retry logic for transient errors:

Use Structured Logging

Use structured logging for better observability:

Reuse the Client

Create a single client instance and reuse it across requests:

Troubleshooting

If you see “The from address domain is not verified”:
  • Verify your domain in the Lettr dashboard
  • Ensure the from address uses the verified domain
  • Wait for DNS propagation (can take up to 48 hours)
  • See Domain Verification for help
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
If requests timeout:
  • Increase the context timeout (default 10 seconds may be too short)
  • Check your network connectivity and firewall settings
  • Verify app.lettr.com is reachable: ping app.lettr.com
  • Consider using a custom HTTP client with longer timeouts
If you see “module not found” or import errors:
  • Run go mod tidy to sync dependencies
  • Verify the import path: github.com/lettr-com/lettr-go
  • Check your Go version is 1.21 or later: go version
  • Clear module cache: go clean -modcache
If you’re hitting rate limits:
  • Implement exponential backoff retry logic (see Best Practices)
  • Use batch sending with controlled concurrency
  • Consider upgrading your Lettr plan for higher limits
  • Spread requests over time instead of bursts

What’s Next

API Reference

Complete API documentation

Templates

Use Lettr-managed templates

Webhooks

Track delivery events

Best Practices

Email deliverability tips