Skip to main content
Send transactional emails from your Go applications using the official Lettr Go SDK. The SDK provides a type-safe, idiomatic Go interface for the Lettr API with full context support and structured error handling. Using Cursor? Jump straight in using this prompt

Why Use the Go SDK?

Rather than making raw HTTP requests, the SDK provides:
  • Type-safe API — Full struct definitions with proper types and validation
  • Context support — All methods accept context.Context for timeouts and cancellation
  • Structured errors — Typed error responses with detailed validation messages
  • Minimal dependencies — Only depends on Go’s standard library and net/http
  • Idiomatic Go — Follows Go conventions and patterns you already know
If you prefer not to use the SDK, you can also send emails via SMTP or make direct HTTP API calls.

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
You’ll also need:
  • Go 1.21 or later installed
  • A verified sending domain in your Lettr dashboard

Quick Setup

Get started in three quick steps: install, configure, and send.
1

Install the SDK

The SDK has minimal dependencies and only requires Go’s standard library. It works with Go 1.21+ and follows semantic versioning.
2

Create a client

Store your API key in environment variables, never hardcode it. API keys use the lttr_ prefix followed by 64 hexadecimal characters.
3

Send your first email

The response includes a RequestID for tracking and the number of accepted recipients.
The sender domain must be verified in your Lettr dashboard before you can send emails. Sending from an unverified domain returns a validation error.

Configuration

Environment Variables

Read your API key from an environment variable:

Using godotenv

Load environment variables from a .env file using the godotenv package:
Create a .env file:
Load it in your application:
Add .env to your .gitignore file to prevent accidentally committing your API key to version control.

Custom HTTP Client

Use a custom HTTP client with custom timeouts or transport settings:

Sending Emails

Basic HTML Email

Send a simple HTML email:

With Display Name

Add a friendly display name to the sender address:

Plain Text Email

Send a plain text email without HTML:

Multipart Emails (HTML + Text)

Send both HTML and plain text versions for maximum compatibility:
Providing both HTML and plain text ensures your emails are readable in all email clients, including text-only clients and accessibility tools.

Explore the SDK

Beyond sending, the SDK manages every Lettr resource:

Templates

Manage Lettr templates and merge tags

Domains

Add, verify, and manage sending domains

Webhooks

Manage webhook endpoints for delivery and engagement events

Audience

Lists, contacts, topics, properties, and segments

Campaigns

List, send, and schedule campaigns

What’s Next

Advanced Features

Learn about attachments, templates, tracking, and more

API Reference

Complete API documentation

Best Practices

Email deliverability tips