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

Prerequisites

Before you start, make sure you have:
  • A Mailrify secret API key (sk_...) for server-side API requests
  • A Mailrify 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/Mailrify/mailrify-go

Initialize clients (mailrify.New)

Create one SDK client for your secret key and one for your public key:
import (
  "os"

  mailrify "github.com/Mailrify/mailrify-go"
)

secretClient := mailrify.New(os.Getenv("MAILRIFY_SECRET_KEY"))
publicClient := mailrify.New(os.Getenv("MAILRIFY_PUBLIC_KEY"))
Set environment variables:
export MAILRIFY_SECRET_KEY="sk_your_secret_key"
export MAILRIFY_PUBLIC_KEY="pk_your_public_key"

Initialize with alias (mailrify.NewClient)

NewClient is an alias for New.
client := mailrify.NewClient("sk_your_secret_key")

Configure base URL and timeout (mailrify.WithBaseURL, mailrify.WithTimeout)

Use this when testing against staging or local environments:
import (
  "time"

  mailrify "github.com/Mailrify/mailrify-go"
)

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

Use a custom HTTP client (mailrify.WithHTTPClient)

import (
  "net/http"
  "time"

  mailrify "github.com/Mailrify/mailrify-go"
)

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

client := mailrify.New(
  "sk_your_secret_key",
  mailrify.WithHTTPClient(httpClient),
  mailrify.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