Email validation
EmailValidation() checks whether an email address can receive mail, wherever its domain is hosted. It also flags disposable, free, role and catch-all addresses.
package main
import (
"context"
"fmt"
"log"
addresszen "go.addresszen.com/sdk"
)
func main() {
client := addresszen.NewClient("ak_test")
res, err := client.EmailValidation(context.Background(), "support@addresszen.com", nil)
if err != nil {
log.Fatal(err)
}
if email := res.Result.AsEmail(); email != nil {
fmt.Println(email.Result, "deliverable:", email.Deliverable)
return
}
fmt.Println("Could not check this address")
}The address is the second argument. Your key needs email validation enabled.
Result
Result is one of three values:
Result | Meaning | Type |
|---|---|---|
deliverable | The mailbox accepts mail | Email, with Deliverable true |
not_deliverable | Mail will bounce, or the domain cannot receive mail | Email, with Deliverable false |
unknown | The API could not check the address | UnknownEmail, with every flag nil |
An Email carries four more flags, each a bool:
Disposable: a throwaway domain, such as temp-mail.orgFree: a free provider, such as Gmail or OutlookRole: a shared mailbox, such as admin@ or support@Catchall: the domain accepts mail for any name, so adeliverableresult proves less
res.Result.AsEmail() returns nil for an unknown result, and AsUnknownEmail() returns it instead.
Corrections
Only when the domain does not resolve or publishes no MX records, Suggestions can hold corrected addresses. The API does not validate them, so check one before you use it. Every other result returns an empty list.
Cost
One lookup for a checked address. An unknown result is free, and so is a domain that does not resolve or has no MX records. The API rejects an address over 320 characters with an *APIError.
See EmailValidation() for the parameters.