sendsend.email

Send email with Go

A server-side call to the SendSend API from your Go app.

  1. Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
  2. Export SENDSEND_API_KEY in the environment that runs the program.
  3. Add this to main.go:
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

func main() {
	body, _ := json.Marshal(map[string]any{
		"from": "Acme <hello@mail.acme.com>", "to": []string{"maria@example.com"},
		"subject": "Hello from Go", "html": "<p>It works!</p>",
	})
	req, _ := http.NewRequest("POST", "https://api.sendsend.email/v1/emails", bytes.NewReader(body))
	req.Header.Set("Authorization", "Bearer "+os.Getenv("SENDSEND_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Idempotency-Key", "welcome-maria-1")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	fmt.Println(res.Status)
}

Use a key that comes from your own data (an order id, say) so a retried call cannot send twice.

Good to know