sendgrid

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sendgrid is a minimal client for the SendGrid v3 Email Address Validation API.

Index

Constants

View Source
const (
	VerdictValid   = "Valid"
	VerdictRisky   = "Risky"
	VerdictInvalid = "Invalid"
)

Verdicts returned by the Email Address Validation API.

View Source
const DefaultBaseURL = "https://api.sendgrid.com"

DefaultBaseURL is the global SendGrid API host. Accounts with EU data residency use https://api.eu.sendgrid.com.

View Source
const DefaultTimeout = 3 * time.Second

DefaultTimeout bounds each request. Cognito waits at most 5 seconds for a trigger, so a slow validation must not use up that time.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Path       string
	StatusCode int
	Body       string
}

APIError is a non-2xx response from the SendGrid API.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the SendGrid API with one API key.

func New

func New(baseURL, apiKey string, httpClient *http.Client) *Client

New returns a client for baseURL (DefaultBaseURL when empty). A nil httpClient uses a client with DefaultTimeout.

func (*Client) ValidateEmail

func (c *Client) ValidateEmail(ctx context.Context, email string) (*Validation, []byte, error)

ValidateEmail validates one address. It returns the parsed result and the raw response body.

type Validation

type Validation struct {
	Email   string  `json:"email"`
	Verdict string  `json:"verdict"`
	Score   float64 `json:"score"`
	Checks  struct {
		Domain struct {
			HasValidAddressSyntax        bool `json:"has_valid_address_syntax"`
			HasMXOrARecord               bool `json:"has_mx_or_a_record"`
			IsSuspectedDisposableAddress bool `json:"is_suspected_disposable_address"`
		} `json:"domain"`
		LocalPart struct {
			IsSuspectedRoleAddress bool `json:"is_suspected_role_address"`
		} `json:"local_part"`
		Additional struct {
			HasKnownBounces     bool `json:"has_known_bounces"`
			HasSuspectedBounces bool `json:"has_suspected_bounces"`
		} `json:"additional"`
	} `json:"checks"`
}

Validation is the result of validating one email address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL