Prerequisites
- Go 1.21+ with
ipapi-goinstalled - A free ip-api.io API key
Fast check with EmailInfo
A lightweight check (no SMTP probe): validates syntax, confirms the domain has MX records, and flags disposable/throwaway providers. Use it inline on sign-up forms.
client := ipapi.NewClient(ipapi.WithAPIKey(os.Getenv("IP_API_IO_KEY")))
ctx := context.Background()
info, err := client.EmailInfo(ctx, "user@example.com")
if err != nil {
log.Fatal(err)
}
fmt.Println(info.Syntax.IsValid) // true
fmt.Println(info.IsDisposable) // false
fmt.Println(info.HasMXRecords) // true
if len(info.MXRecords) > 0 {
fmt.Println(info.MXRecords[0].Hostname)
} Full SMTP verification with ValidateEmail
Advanced verification that connects to the mail server to confirm the mailbox is deliverable, and adds role-account, free-provider, catch-all and Gravatar signals.
result, _ := client.ValidateEmail(ctx, "user@example.com")
fmt.Println(result.Reachable) // "yes" | "no" | "unknown"
if result.SMTP != nil {
fmt.Println(result.SMTP.Deliverable, result.SMTP.CatchAll)
}
fmt.Println(result.Disposable) // false
fmt.Println(result.RoleAccount) // false (e.g. info@, support@)
fmt.Println(result.Free) // false (e.g. gmail.com)
fmt.Println(result.Suggestion) // typo fix, e.g. "user@gmail.com" Clean a list with ValidateEmailBatch
Advanced-validate up to 100 addresses in one request — the building block for email list cleaning. Returns an error if the slice is empty or longer than 100.
batch, _ := client.ValidateEmailBatch(ctx, []string{
"user@example.com",
"fake@mailinator.com",
})
fmt.Println(batch.TotalProcessed) // 2
fmt.Println(batch.SuccessfulValidations) // 2
for email, result := range batch.Results {
fmt.Println(email, result.Reachable, result.Disposable)
}