ReachScore Docs

Quickstart: Go

Integrate ReachScore into your Go application.

1

Install the SDK

Install the official ReachScore Go SDK:

go get github.com/reachscore/reachscore-go
2

Initialize the client

Create a new client instance with your API key:

package main

import (
    "os"
    "github.com/reachscore/reachscore-go"
)

func main() {
    client := reachscore.NewClient(os.Getenv("REACHSCORE_API_KEY"))
}
3

Create a test

Create a new deliverability test:

ctx := context.Background()

test, err := client.Tests.Create(ctx, &reachscore.TestCreateParams{
    FromAddress: "notifications@yourcompany.com",
    Subject:     "Test email deliverability",
})
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Send your email to: %s\n", test.TestAddress)
// test.TestAddress = "test_7xK2mN9p@inbound.reachscore.co"
4

Get the results

After sending your email, retrieve the test results:

// Poll for results (or use webhooks)
result, err := client.Tests.Get(ctx, test.ID)
if err != nil {
    log.Fatal(err)
}

if result.Status == "completed" {
    fmt.Printf("Deliverability Score: %d\n", result.Score)
    fmt.Printf("Grade: %s\n", result.Grade)
    fmt.Printf("SPF: %s\n", result.AuthResults.SPF)
    fmt.Printf("DKIM: %s\n", result.AuthResults.DKIM)
    fmt.Printf("DMARC: %s\n", result.AuthResults.DMARC)
}

Complete Example

Here is a full working example that creates a test and waits for results:

package main

import (
    "context"
    "fmt"
    "log"
    "os"
    "time"

    "github.com/reachscore/reachscore-go"
)

func main() {
    client := reachscore.NewClient(os.Getenv("REACHSCORE_API_KEY"))
    ctx := context.Background()

    // Create the test
    test, err := client.Tests.Create(ctx, &reachscore.TestCreateParams{
        FromAddress: "notifications@yourcompany.com",
        Subject:     "Weekly newsletter",
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Test created: %s\n", test.ID)
    fmt.Printf("Send email to: %s\n", test.TestAddress)

    // Wait for results (in production, use webhooks instead)
    for {
        result, err := client.Tests.Get(ctx, test.ID)
        if err != nil {
            log.Fatal(err)
        }

        fmt.Printf("Status: %s\n", result.Status)

        if result.Status == "completed" {
            fmt.Printf("Score: %d/100 (Grade: %s)\n", result.Score, result.Grade)
            fmt.Printf("Auth: SPF=%s, DKIM=%s, DMARC=%s\n",
                result.AuthResults.SPF,
                result.AuthResults.DKIM,
                result.AuthResults.DMARC)
            break
        }

        if result.Status == "failed" {
            fmt.Println("Test failed")
            break
        }

        time.Sleep(5 * time.Second)
    }
}

Error Handling

The SDK returns typed errors for different error scenarios:

import "github.com/reachscore/reachscore-go/errors"

test, err := client.Tests.Get(ctx, "test_invalid_id")
if err != nil {
    var notFoundErr *errors.NotFoundError
    var rateLimitErr *errors.RateLimitError
    var authErr *errors.AuthenticationError

    switch {
    case errors.As(err, &notFoundErr):
        fmt.Printf("Test not found: %s\n", notFoundErr.Message)
    case errors.As(err, &rateLimitErr):
        fmt.Printf("Rate limited. Retry after %d seconds\n", rateLimitErr.RetryAfter)
    case errors.As(err, &authErr):
        fmt.Printf("Auth error: %s\n", authErr.Message)
    default:
        log.Fatal(err)
    }
}

Context and Timeouts

All API methods accept a context for cancellation and timeouts:

// With timeout
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

test, err := client.Tests.Create(ctx, &reachscore.TestCreateParams{
    FromAddress: "notifications@yourcompany.com",
})
if err != nil {
    if ctx.Err() == context.DeadlineExceeded {
        fmt.Println("Request timed out")
    }
}