# Groundmail with Go

Use the Go SDK in HTTP handlers, workers, cron jobs, or any server-side Go service where your API key can stay private.

## 1. Install the SDK

```bash
go get github.com/Groundmail/groundmail-sdks/go@v0.10.0
```

## 2. Configure your API key

```bash
export GROUNDMAIL_API_KEY=gm_your_key_here
```

## 3. Send an email

```go
package main

import (
	"fmt"
	"log"
	"os"

	groundmail "github.com/Groundmail/groundmail-sdks/go"
)

func main() {
	client, err := groundmail.New(os.Getenv("GROUNDMAIL_API_KEY"))
	if err != nil {
		log.Fatal(err)
	}

	result, err := client.Emails.Send(map[string]any{
		"from":    "ops@yourdomain.com",
		"to":      "user@example.com",
		"subject": "Your receipt",
		"html":    "<p>Thanks for your purchase.</p>",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result["id"], result["status"])
}
```

## Resources

The client includes thin wrappers for common API resources:

- `client.Emails` — send, batch, list, cancel, resend, test webhooks, deliverability insights
- `client.Domains` — create, verify, apply DNS, update, delete
- `client.Webhooks` — CRUD for webhook endpoints
- `client.Templates` — CRUD plus publish
- `client.Suppressions` — list, create, remove
- `client.Validate(email, opts)` and `client.ValidateBatch(emails, opts)` — check addresses before you accept them ([validation](https://docs.groundmail.dev/validation)); `&groundmail.ValidateOptions{MailboxCheck: true}` also confirms the mailbox exists

See the [API reference](https://docs.groundmail.dev/emails) for request fields. The Go SDK accepts the same JSON shapes as the REST API.

## Source

Package source lives in [`go/`](https://github.com/Groundmail/groundmail-sdks/tree/main/go) in the public [groundmail-sdks](https://github.com/Groundmail/groundmail-sdks) repository (mirrored from the private app monorepo on release).
