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

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:

Install

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:
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:
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.
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:
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)

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