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

# Overview

> Install and initialize the MailGlyph Go SDK.

Use the official Go SDK to call the MailGlyph API from server-side apps.

* Go module: [github.com/MailGlyph/mailglyph-go](https://pkg.go.dev/github.com/MailGlyph/mailglyph-go)
* GitHub repository: [MailGlyph Go SDK](https://github.com/MailGlyph/mailglyph-go)

## Prerequisites

Before you start, make sure you have:

* A MailGlyph **secret API key** (`sk_...`) for server-side API requests
* A MailGlyph **public API key** (`pk_...`) for event tracking (`/v1/track`)
* At least one **verified sending domain** for email sending

Setup links:

* [MailGlyph API keys dashboard](https://app.mailglyph.com/api-keys)
* [MailGlyph domains dashboard](https://app.mailglyph.com/domains)
* [API keys guide](https://docs.mailglyph.com/guides/api-keys.md)
* [Domain verification guide](https://docs.mailglyph.com/guides/verifying-domains.md)

## Install

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

## Initialize clients (`mailglyph.New`)

Create one SDK client for your secret key and one for your public key:

```go theme={null}
import (
  "os"

  mailglyph "github.com/MailGlyph/mailglyph-go"
)

secretClient := mailglyph.New(os.Getenv("MAILGLYPH_SECRET_KEY"))
publicClient := mailglyph.New(os.Getenv("MAILGLYPH_PUBLIC_KEY"))
```

Set environment variables:

```bash theme={null}
export MAILGLYPH_SECRET_KEY="sk_your_secret_key"
export MAILGLYPH_PUBLIC_KEY="pk_your_public_key"
```

## Initialize with alias (`mailglyph.NewClient`)

`NewClient` is an alias for `New`.

```go theme={null}
client := mailglyph.NewClient("sk_your_secret_key")
```

## Configure base URL and timeout (`mailglyph.WithBaseURL`, `mailglyph.WithTimeout`)

Use this when testing against staging or local environments:

```go theme={null}
import (
  "time"

  mailglyph "github.com/MailGlyph/mailglyph-go"
)

client := mailglyph.New(
  "sk_your_secret_key",
  mailglyph.WithBaseURL("https://api.mailglyph.com"),
  mailglyph.WithTimeout(30*time.Second),
)
```

## Use a custom HTTP client (`mailglyph.WithHTTPClient`)

```go theme={null}
import (
  "net/http"
  "time"

  mailglyph "github.com/MailGlyph/mailglyph-go"
)

httpClient := &http.Client{Timeout: 20 * time.Second}

client := mailglyph.New(
  "sk_your_secret_key",
  mailglyph.WithHTTPClient(httpClient),
  mailglyph.WithTimeout(10*time.Second),
)
```

## Key usage rules

The Go SDK enforces key restrictions automatically:

* `pk_*` keys can only call `Events.Track`
* `sk_*` keys can call non-track endpoints, including `Events.GetNames` and `Events.ListNames`

Unlike the Node.js SDK, the Go SDK does not expose a `keyType` property on the client.

## Next pages

* [Emails examples](https://docs.mailglyph.com/sdks/go/emails.md)
* [Email Validation examples](https://docs.mailglyph.com/sdks/go/email-validation.md)
* [Events examples](https://docs.mailglyph.com/sdks/go/events.md)
* [Contacts examples](https://docs.mailglyph.com/sdks/go/contacts.md)
* [Segments examples](https://docs.mailglyph.com/sdks/go/segments.md)
* [Campaigns examples](https://docs.mailglyph.com/sdks/go/campaigns.md)
* [Error handling](https://docs.mailglyph.com/sdks/go/errors.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.