EmailCheckerEmailChecker

Documentação · Go

Validar email em Go

Go tem net/http excelente na stdlib — não precisa de nenhuma biblioteca externa. Os exemplos abaixo são puro Go, prontos pra usar em qualquer projeto.

Instalação (go mod)

bash
# Nenhuma dependência externa.
# Apenas:
go mod init seu-projeto

Single · POST /validate/single

Validar 1 email

Endpoint síncrono. Retorna em 1–3 segundos com result, score, reason e atributos. Custa 1 crédito por chamada bem-sucedida.

go
// main.go — validate_single
package main

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

const baseURL = "https://app.emailchecker.email/api/v1"

type validateResp struct {
	Result string  `json:"result"`
	Score  *int    `json:"score"`
	Reason *string `json:"reason"`
}

func validateEmail(email string) (*validateResp, error) {
	apiKey := os.Getenv("EMAILCHECKER_API_KEY")
	body, _ := json.Marshal(map[string]string{"email": email})

	req, err := http.NewRequest("POST", baseURL+"/validate/single", bytes.NewReader(body))
	if err != nil {
		return nil, err
	}
	req.Header.Set("Authorization", "Bearer "+apiKey)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 15 * time.Second}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode >= 400 {
		return nil, fmt.Errorf("API error: %d", resp.StatusCode)
	}
	var result validateResp
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return nil, err
	}
	return &result, nil
}

func main() {
	r, err := validateEmail("joao@empresa.com.br")
	if err != nil {
		panic(err)
	}
	fmt.Println("Result:", r.Result)
}

Batch · POST /validate/batch

Validar em lote

Endpoint async. Submete array de emails, retorna job_id. Use webhook (recomendado) ou polling pra pegar resultado. Suporta até 100k emails por job.

go
// batch.go
type batchSubmitReq struct {
	Emails     []string `json:"emails"`
	WebhookURL string   `json:"webhook_url,omitempty"`
}

type batchSubmitResp struct {
	JobID string `json:"job_id"`
}

func submitBatch(emails []string, webhookURL string) (string, error) {
	apiKey := os.Getenv("EMAILCHECKER_API_KEY")
	payload := batchSubmitReq{Emails: emails, WebhookURL: webhookURL}
	body, _ := json.Marshal(payload)

	req, _ := http.NewRequest("POST", baseURL+"/validate/batch", bytes.NewReader(body))
	req.Header.Set("Authorization", "Bearer "+apiKey)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 30 * time.Second}
	resp, err := client.Do(req)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	var out batchSubmitResp
	if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
		return "", err
	}
	return out.JobID, nil
}

Webhook handler

Receber notificação do job

Quando o batch termina, a gente faz POST pra URL que você passou em webhook_url. Retry automático em até 3 tentativas (1s, 5s, 30s) se você responder com erro 5xx.

go
// webhook.go
type webhookPayload struct {
	JobID   string `json:"job_id"`
	Status  string `json:"status"`
	Results []struct {
		Email  string `json:"email"`
		Result string `json:"result"`
	} `json:"results"`
}

func webhookHandler(w http.ResponseWriter, r *http.Request) {
	var payload webhookPayload
	if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
		http.Error(w, "bad request", 400)
		return
	}
	if payload.Status != "completed" {
		w.Write([]byte(`{"ok":true}`))
		return
	}
	for _, res := range payload.Results {
		if res.Result == "deliverable" {
			// salva no banco, dispara worker, etc.
		}
	}
	w.Write([]byte(`{"ok":true}`))
}

// router: http.HandleFunc("/webhook/ec", webhookHandler)

Boas práticas

Mais linguagens

Exemplos em outras linguagens

Comece agora

Pronto pra parar de mandar email pra endereço morto?

Comece grátis com 500 créditos. Sem cartão, sem compromisso.