> ## Documentation Index
> Fetch the complete documentation index at: https://jetemail.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Go

> Official JetEmail Go SDK for transactional email

# Go SDK

The **[jetemail-go](https://github.com/jetemail/jetemail-go)** module is the official Go SDK for JetEmail transactional email (MIT license, **Go 1.21+**).

Create a **transactional** API key in the dashboard: **Outbound** → **Keys** → Add API key. Use that key with the SDK.

## Installation

```bash theme={null}
go get github.com/jetemail/jetemail-go
```

## Quick start

```go theme={null}
package main

import (
    "fmt"
    "github.com/jetemail/jetemail-go"
)

func main() {
    client := jetemail.New("your-transactional-api-key")

    result, err := client.Email.Send(&jetemail.SendEmailOptions{
        From:    "Your App <hello@yourdomain.com>",
        To:      "user@example.com",
        Subject: "Welcome!",
        HTML:    "<h1>Welcome!</h1>",
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(result.ID)
}
```

Use a `From` address on a **verified domain** (see [Getting started](/transactional-email/getting-started)).

## Constructor

```go theme={null}
// API key string
client := jetemail.New("your-transactional-api-key")

// Or with options
client := jetemail.New("your-transactional-api-key", jetemail.WithBaseURL("https://api.jetemail.com"))
```

## `client.Email.Send(options)`

Send a single email.

| Field                  | Required | Description                              |
| ---------------------- | -------- | ---------------------------------------- |
| `From`                 | ✓        | Sender, e.g. `"Name <email@domain.com>"` |
| `To`                   | ✓        | Recipient(s), string or slice (max 50)   |
| `Subject`              | ✓        | Subject line                             |
| `HTML`                 | \*       | HTML body (need `HTML` and/or `Text`)    |
| `Text`                 | \*       | Plain text (need `HTML` and/or `Text`)   |
| `CC`, `BCC`, `ReplyTo` |          | Recipients (max 50 each)                 |
| `Headers`              |          | Custom headers map                       |
| `Attachments`          |          | Attachments (max 40MB total)             |

Response shape: `SendEmailResponse{ ID string, Response string }`.

## `client.Batch.Send(emails)`

Send up to **100** emails in one request. Returns `Summary` (`Total`, `Successful`, `Failed`) and `Results` per message.

```go theme={null}
result, err := client.Batch.Send([]*jetemail.SendEmailOptions{
    {
        From:    "you@example.com",
        To:      "alice@example.com",
        Subject: "Hello Alice",
        HTML:    "<p>Hi Alice!</p>",
    },
    {
        From:    "you@example.com",
        To:      "bob@example.com",
        Subject: "Hello Bob",
        HTML:    "<p>Hi Bob!</p>",
    },
})
```

## Attachments

```go theme={null}
result, err := client.Email.Send(&jetemail.SendEmailOptions{
    From:    "you@example.com",
    To:      "recipient@example.com",
    Subject: "Invoice",
    HTML:    "<p>Please find your invoice attached.</p>",
    Attachments: []jetemail.Attachment{
        jetemail.AttachmentFromPath("/path/to/invoice.pdf"),
        jetemail.AttachmentFromContent([]byte("Hello World"), "hello.txt"),
    },
})
```

## Error handling

```go theme={null}
result, err := client.Email.Send(&jetemail.SendEmailOptions{...})
if err != nil {
    var apiErr *jetemail.JetEmailError
    if errors.As(err, &apiErr) {
        fmt.Println(apiErr.StatusCode, apiErr.Message, apiErr.Response)
    }
}
```

Common status codes: **400** invalid request, **401** bad/missing API key, **500** server error.

***

For additional examples and the full option list, see the **[GitHub repository](https://github.com/jetemail/jetemail-go)**. REST details: [API reference](/api-reference/introduction).
