Go SDK
Official Go SDK for the eusend API. Zero dependencies, context-aware, and shaped to mirror resend-go.
Official Go SDK for the eusend API. Its shape mirrors
resend-go, so migrating from Resend is
largely a resend → eusend rename. Zero dependencies (standard library only),
context.Context-aware, and safe for concurrent use. Requires Go 1.21+.
Installation
go get github.com/eusend-dev/eusend-goGetting started
Create a client with your API key. Pass an empty string to read EUSEND_API_KEY
from the environment.
import eusend "github.com/eusend-dev/eusend-go"
client := eusend.NewClient("eu_live_...") // or NewClient("") to read EUSEND_API_KEYEvery method has a WithContext variant that takes a context.Context as its
first argument (e.g. client.Emails.SendWithContext(ctx, params)). The
context-free forms use context.Background(). Optional pointer fields have
helpers: eusend.Bool(true), eusend.String("x").
Sending an email
From and To are required; provide at least one of Html, Text, or TemplateId.
sent, err := client.Emails.Send(&eusend.SendEmailRequest{
// From accepts a bare email or a display-name form: "Acme <you@yourdomain.com>"
From: "hello@yourdomain.com",
To: []string{"customer@example.com"},
Subject: "Your order is confirmed",
Html: "<p>Thanks for your order!</p>",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(sent.Id) // 9a8b7c6d-...Send options
| Field | Type | Description |
|---|---|---|
From | string | Sender address — bare email or "Name <email>" |
To Cc Bcc ReplyTo | []string | Max 50 each |
Subject | string | Email subject |
Html / Text | string | HTML / plain-text body |
TemplateId | string | ID of a saved template |
Variables | map[string]any | Template variable substitutions (HTML-escaped) |
Headers | map[string]string | Custom headers; no line breaks in names or values |
TrackOpens / TrackClicks | *bool | Nil uses your organization default; eusend.Bool(true) to enable (default is off unless changed) |
Attachments | []*Attachment | Up to 20, 10 MB combined. See below. |
ScheduledAt | string | Schedule for a future time, at most 30 days out |
Attachments
Provide Content (raw bytes, base64-encoded on the wire) or Path (a public
URL fetched at send time; a message's Path files must download within 15 seconds in
total). Set ContentId for an inline <img src="cid:...">.
pdf, _ := os.ReadFile("invoice.pdf")
client.Emails.Send(&eusend.SendEmailRequest{
From: "you@yourdomain.com",
To: []string{"customer@example.com"},
Subject: "Your invoice",
Html: "<p>Attached.</p>",
Attachments: []*eusend.Attachment{
{Filename: "invoice.pdf", Content: pdf, ContentType: "application/pdf"},
},
})Idempotent sends
client.Emails.SendWithOptions(ctx, params, &eusend.SendEmailOptions{
IdempotencyKey: "receipt-" + orderID,
})Retrying with the same key never sends a duplicate and returns the original ID. Send
generates a key per call when you pass none, so the SDK's automatic retries
never send twice; pass your own when your code may retry too, such as after a crash.
Batch send
Send up to 100 emails in a single request. Attachments and scheduling are
stripped (not supported on the batch endpoint). Results map positionally to the
input: queued items carry Id, rejected items carry Error and Code.
res, _ := client.Batch.Send([]*eusend.SendEmailRequest{
{From: "you@yourdomain.com", To: []string{"alice@example.com"}, Subject: "Hi", Html: "<p>Hi</p>"},
{From: "you@yourdomain.com", To: []string{"bob@example.com"}, Subject: "Hi", Html: "<p>Hi</p>"},
})
for _, r := range res.Data {
if r.Id != "" {
fmt.Println("queued", r.Id)
} else {
fmt.Printf("failed: %s (%s)\n", r.Error, r.Code)
}
}SendWithOptions makes a batch safe to retry (Send generates a key per call otherwise).
The key is applied per item by position, so a retry must send the items in the same order.
client.Batch.SendWithOptions(ctx, emails, &eusend.BatchSendOptions{
IdempotencyKey: "digest-" + runID,
})Scheduled sends
ScheduledAt accepts an ISO 8601 string or natural language like "in 1 hour"
(at most 30 days out), parsed server-side in UTC.
sent, _ := client.Emails.Send(&eusend.SendEmailRequest{
From: "you@yourdomain.com", To: []string{"customer@example.com"},
Subject: "Your trial ends tomorrow", Html: "<p>Reminder.</p>",
ScheduledAt: "in 1 hour",
})
client.Emails.Update(&eusend.UpdateEmailRequest{Id: sent.Id, ScheduledAt: "2026-07-04T09:00:00Z"})
client.Emails.Cancel(sent.Id)Retrieve & list emails
email, _ := client.Emails.Get("9a8b7c6d-...")
fmt.Println(email.Status, email.Events[0].Type)
page, _ := client.Emails.List(&eusend.ListEmailsOptions{Status: "delivered", Limit: 50})
for _, e := range page.Data {
fmt.Println(e.Id, e.Subject)
}
// page.NextCursor -> pass as ListEmailsOptions{Cursor: ...} for the next pageDomains
created, _ := client.Domains.Create(&eusend.CreateDomainRequest{Name: "yourdomain.com"})
for _, r := range created.Records { // every DNS record to add
fmt.Println(r.Type, r.Name, r.Value)
}
client.Domains.Verify(created.Id) // after publishing the records
client.Domains.List()
client.Domains.Get(created.Id)
client.Domains.Remove(created.Id)Receiving email
Every paid workspace can receive email at its own eusend.app host.
Use a full-access API key. Subscribe a webhook to email.received, then use its
inbound_email_id to fetch the message. Lists are newest first by default; the example
below requests oldest first. Keep the same order and recipient filter while paging.
address, err := client.Inbound.Address()
page, err := client.Inbound.List(&eusend.ListInboundOptions{Limit: 20, Order: "asc"})
email, err := client.Inbound.Get(inboundEmailId)
raw, err := client.Inbound.Raw(inboundEmailId) // []byte
attachment, err := client.Inbound.Attachment(inboundEmailId, 0) // []byteCheck each error before using the result. Pass page.NextCursor as Cursor to get the next
page, or set To to filter by recipient. email includes text, HTML, headers, attachment
metadata and authentication results. Treat received content as untrusted input.
These methods also have WithContext variants.
For a custom receiving domain:
inbound, err := client.Domains.EnableInbound(domainId, &eusend.EnableInboundRequest{Subdomain: "in"})
if err != nil {
log.Fatal(err)
}
fmt.Println(inbound.Record) // publish this MX record at your DNS provider
_, err = client.Domains.DisableInbound(domainId)API keys
key, _ := client.ApiKeys.Create(&eusend.CreateApiKeyRequest{Name: "Production"})
fmt.Println(key.Key) // eu_live_... — returned only once
client.ApiKeys.Create(&eusend.CreateApiKeyRequest{Name: "Sandbox", TestMode: true}) // eu_test_... key
// Send-only key, restricted to one domain. Omit DomainId for any verified domain.
client.ApiKeys.Create(&eusend.CreateApiKeyRequest{
Name: "Billing service",
Permission: eusend.PermissionSendingAccess,
DomainId: domainId,
})
client.ApiKeys.List() // prefixes only
client.ApiKeys.Remove(key.Id)Templates
{{variable}} placeholders are substituted at send time; values are HTML-escaped.
tpl, _ := client.Templates.Create(&eusend.CreateTemplateRequest{
Name: "Welcome email",
Subject: "Welcome, {{name}}!",
Html: "<h1>Hi {{name}}</h1><p>Welcome to {{product}}.</p>",
})
client.Emails.Send(&eusend.SendEmailRequest{
From: "you@yourdomain.com", To: []string{"customer@example.com"},
TemplateId: tpl.Id,
Variables: map[string]any{"name": "Jane", "product": "Acme"},
})
client.Templates.List()
client.Templates.Get(tpl.Id)
client.Templates.Update(tpl.Id, &eusend.UpdateTemplateRequest{Subject: eusend.String("New subject")})
html, _ := client.Templates.Preview(tpl.Id, map[string]any{"first_name": "Alex"}) // rendered HTML
client.Templates.Remove(tpl.Id)Audiences & contacts
Contact operations are grouped under Audiences (they live under a specific audience).
audience, _ := client.Audiences.Create(&eusend.CreateAudienceRequest{Name: "Newsletter"})
client.Audiences.CreateContact(audience.Id, &eusend.CreateContactRequest{
Email: "user@example.com", FirstName: "Jane",
})
// Bulk upsert (up to 1,000). Unsubscribed and CreatedAt are for migrating a list
// in — an import can add an opt-out but never clear one.
client.Audiences.BatchCreateContacts(audience.Id, []*eusend.CreateContactRequest{
{Email: "alice@example.com", FirstName: "Alice"},
{Email: "bob@example.com", Unsubscribed: eusend.Bool(true), CreatedAt: "2024-02-01T10:00:00Z"},
})
// Bulk delete by id (up to 1,000). Removes them from the audience — not an unsubscribe.
client.Audiences.BatchDeleteContacts(audience.Id, []string{contactId})
page, _ := client.Audiences.ListContacts(audience.Id, &eusend.ListContactsOptions{
Subscribed: eusend.Bool(true), Search: "gmail.com",
})
contact := page.Data[0]
client.Audiences.UpdateContact(audience.Id, contact.Id, &eusend.UpdateContactRequest{
Unsubscribed: eusend.Bool(true),
})
client.Audiences.GetContact(audience.Id, contact.Id)
client.Audiences.RemoveContact(audience.Id, contact.Id)
client.Audiences.List()
client.Audiences.Get(audience.Id) // includes ContactCount
client.Audiences.Update(audience.Id, &eusend.UpdateAudienceRequest{Name: "Product updates"})
client.Audiences.Remove(audience.Id)Topics
Kinds of email a contact can subscribe to and leave independently, so an unsubscribe can be a preference change. See Topics.
topic, _ := client.Topics.Create(&eusend.CreateTopicRequest{
Name: "Product updates",
// "opt_in" reaches everyone until they leave; "opt_out" reaches nobody until they
// join. Fixed at creation.
DefaultSubscription: "opt_in",
Description: eusend.String("New features and changes, about once a month."),
Visibility: "public",
})
client.Topics.List()
client.Topics.Get(topic.Id)
client.Topics.Update(topic.Id, &eusend.UpdateTopicRequest{Visibility: eusend.String("private")})
// Record an explicit preference for one contact.
client.Topics.Subscribe(topic.Id, contactId, true)
// Forget the choice entirely, back to the topic default — not the same as false.
client.Topics.ClearSubscription(topic.Id, contactId)
client.Topics.Remove(topic.Id)
// Scope a broadcast to it.
client.Broadcasts.Create(&eusend.CreateBroadcastRequest{
Name: "October update",
AudienceId: audience.Id,
TopicId: topic.Id,
From: "hello@acme.com",
Subject: "What shipped in October",
Html: "<p>Hi {{first_name}}…</p>",
})Suppressions
Addresses the account will not send to. Hard bounces and spam complaints are added automatically — these methods cover the ones you manage yourself. See Suppressions for the full API.
// What's blocked, and why
client.Suppressions.List(&eusend.ListSuppressionsOptions{
Reason: eusend.SuppressionReasonBounce, Limit: 50,
})
client.Suppressions.List(&eusend.ListSuppressionsOptions{Email: "@acme.com"})
// Stop sending to an address. Already suppressed? The existing entry comes back
// unchanged — a manual add never rewrites a real bounce or complaint.
client.Suppressions.Create(&eusend.CreateSuppressionRequest{Email: "opted-out@example.com"})
// Import up to 1,000 per call — do this before your first send when migrating
res, _ := client.Suppressions.Import([]*eusend.SuppressionImportItem{
{Email: "one@example.com"},
{Email: "two@example.com", Reason: eusend.SuppressionReasonComplaint},
})
fmt.Println(res.Count, res.AlreadySuppressed, res.Duplicates)
// Un-suppress by entry id or by address; export the whole list as CSV
client.Suppressions.Remove("invalid@example.com")
csv, _ := client.Suppressions.Export()Reputation
Your bounce and complaint rates exactly as the sending limits judge them — what counted, what did not, and how far you are from a halved daily limit or a pause. See how rates are judged. Not available to sending-only keys.
r, err := client.Reputation.Get()
if err != nil {
log.Fatal(err)
}
fmt.Println(r.State) // healthy, warning, limited or paused
if r.Next != nil && r.Next.Bounces != nil && *r.Next.Bounces <= 3 {
log.Printf("%d more bounces would move this account to %s", *r.Next.Bounces, r.Next.State)
}Broadcasts
{{first_name}}, {{last_name}}, {{full_name}}, and {{email}} are available
per recipient, and RFC 8058 one-click unsubscribe headers are added automatically.
bc, _ := client.Broadcasts.Create(&eusend.CreateBroadcastRequest{
Name: "May newsletter",
AudienceId: audience.Id,
From: "Sivert <hello@yourdomain.com>",
Subject: "May update",
Html: "<p>Hi {{first_name}}, your monthly update is here...</p>",
TrackOpens: eusend.Bool(true), // omit to use your organization default
})
client.Broadcasts.Test(bc.Id, &eusend.TestBroadcastRequest{To: []string{"you@yourdomain.com"}}) // preview to your own domain
client.Broadcasts.Send(bc.Id, nil) // send now
client.Broadcasts.Send(bc.Id, &eusend.SendBroadcastRequest{ScheduledAt: "2026-06-01T09:00:00Z"}) // or schedule
client.Broadcasts.Cancel(bc.Id)
client.Broadcasts.List()
client.Broadcasts.Get(bc.Id) // includes delivery stats
client.Broadcasts.Update(bc.Id, &eusend.UpdateBroadcastRequest{Subject: eusend.String("Updated")})
client.Broadcasts.Remove(bc.Id)Webhooks
hook, _ := client.Webhooks.Create(&eusend.CreateWebhookRequest{
Url: "https://yourapp.com/webhooks/eusend",
Events: []string{"email.sent", "email.delivered", "email.bounced", "email.complained"},
// or: Events: []string{"*"} to receive everything
})
fmt.Println(hook.Secret) // signing secret — store it securely; GetSecret reads it again
client.Webhooks.List()
client.Webhooks.Get(hook.Id) // includes recent deliveries
client.Webhooks.Update(hook.Id, &eusend.UpdateWebhookRequest{Events: []string{"email.bounced"}})
client.Webhooks.GetSecret(hook.Id) // current signing secret
client.Webhooks.RotateSecret(hook.Id) // new secret, effective immediately
client.Webhooks.Remove(hook.Id)Verifying webhook signatures
Every delivery is signed with HMAC-SHA256 over {webhook-id}.{webhook-timestamp}.{body}:
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
)
func verify(r *http.Request, body []byte, secret string) bool {
signed := r.Header.Get("webhook-id") + "." + r.Header.Get("webhook-timestamp") + "." + string(body)
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(signed))
expected := "v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil))
return hmac.Equal([]byte(r.Header.Get("webhook-signature")), []byte(expected))
}Retries
The client retries a failed request up to twice by default:
- A
429 RATE_LIMITEDis retried after theRetry-Afterthe API sends. - A network failure or a
5xxis retried, with backoff, on reads and on sends (which carry an idempotency key). Other writes are not repeated, since doing them twice could matter. DAILY_LIMIT_EXCEEDED,MONTHLY_LIMIT_EXCEEDEDand aRetry-Afterover 60 seconds are returned to you straight away.
Waits honour the request's context, so a deadline or cancellation ends them.
client := eusend.NewClient("eu_live_...")
client.MaxRetries = 5 // 0 turns retries offError handling
Every method returns (result, error). Any non-2xx response, and any network
failure, is an *eusend.Error. On a 429 that is returned to you, RetryAfter,
RateLimitReset, and RateLimitRemaining are populated from the response headers.
sent, err := client.Emails.Send(params)
if err != nil {
var apiErr *eusend.Error
if errors.As(err, &apiErr) {
fmt.Println(apiErr.Code) // "MONTHLY_LIMIT_EXCEEDED"
fmt.Println(apiErr.Message) // "Monthly send limit exceeded"
fmt.Println(apiErr.StatusCode) // 429 (0 for a network failure)
if apiErr.Code == eusend.CodeMonthlyLimitExceeded {
// back off and retry later
}
}
return
}| Code constant | Wire value | Status |
|---|---|---|
CodeUnauthorized | UNAUTHORIZED | 401 |
CodeForbidden | FORBIDDEN | 403 |
CodeNotFound | NOT_FOUND | 404 |
CodeValidationError | VALIDATION_ERROR | 400 |
CodeBadRequest | BAD_REQUEST | 400 |
CodePayloadTooLarge | PAYLOAD_TOO_LARGE | 413 |
CodeConflict | CONFLICT | 409 |
CodeRateLimited | RATE_LIMITED | 429 |
CodeMonthlyLimitExceeded | MONTHLY_LIMIT_EXCEEDED | 429 |
CodeDailyLimitExceeded | DAILY_LIMIT_EXCEEDED | 429 |
CodePlanLimitExceeded | PLAN_LIMIT_EXCEEDED | 403 |
CodeDomainNotVerified | DOMAIN_NOT_VERIFIED | 403 |
CodeSendingSuspended | SENDING_SUSPENDED | 403 |
CodeAccountRestricted | ACCOUNT_RESTRICTED | 403 |
CodeWorkspaceInactive | WORKSPACE_INACTIVE | 403 |
CodeSenderNotPermitted | SENDER_NOT_PERMITTED | 403 |
CodeListSendHeld | LIST_SEND_HELD | 403 |
CodeBroadcastHeld | BROADCAST_HELD | 403 |
CodeAllSuppressed | ALL_SUPPRESSED | 422 |
CodeRecipientDomainUndeliverable | RECIPIENT_DOMAIN_UNDELIVERABLE | 422 |
CodeServicePaused | SERVICE_PAUSED | 503 |
CodeAttachmentStorageErr | ATTACHMENT_STORAGE_ERROR | 503 |
CodeInternalError | INTERNAL_ERROR | 500 |
CodeApplicationError | application_error | — (network failure) |
View the full source and changelog on GitHub.
Python SDK
Official Python SDK for the eusend API. Zero HTTP dependencies, typed, and shaped to mirror resend-python.
MCP server
Connect eusend to any AI coding tool over the Model Context Protocol — send email and manage domains, audiences, and broadcasts from Claude, Cursor, Codex, and other MCP clients.