Docs

Verify emails from Go

A working helper that verifies one address from Go. ValidReach does not publish an official SDK for this language. The examples call the REST API directly, which is the supported way to integrate.

Before you start

Create an API key under Settings → API keys and keep it in an environment variable named VALIDREACH_API_KEY on your server. Never ship it in browser or mobile code.

Verify one address

package validreach

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

type Result struct {
	Email         string `json:"email"`
	Status        string `json:"status"`
	IsDeliverable *bool  `json:"is_deliverable"`
	Reason        string `json:"reason"`
	CreditsUsed   int    `json:"credits_used"`
	Retryable     bool   `json:"retryable"`
}

func Verify(email string) (*Result, error) {
	payload, _ := json.Marshal(map[string]string{"email": email})
	req, err := http.NewRequest("POST", "https://validreach.dev/api/v1/verify/single", bytes.NewReader(payload))
	if err != nil {
		return nil, err
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VALIDREACH_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	if res.StatusCode == 402 || res.StatusCode == 429 {
		return nil, fmt.Errorf("verification unavailable: HTTP %d", res.StatusCode)
	}
	var body struct {
		Success bool    `json:"success"`
		Message string  `json:"message"`
		Data    *Result `json:"data"`
	}
	if err := json.NewDecoder(res.Body).Decode(&body); err != nil {
		return nil, err
	}
	if !body.Success {
		return nil, fmt.Errorf("request failed: %s", body.Message)
	}
	return body.Data, nil
}

Handle the result

Branch on data.status. Treat invalid and disposable as rejections, retry unknown later when retryable is true (unknown is not billed), and decide on catchall, risky and role by your own policy. HTTP 402 means out of credits and 429 means rate limited.