You will need a zerobounce account to get started.
Once you get an account, you will need to get an api key
to use it in the API calls.
Require the package
$ go get https://github.com/twisted1919/zerobounce-go
Requires Go >= 1.8
package main
import (
"fmt"
"github.com/twisted1919/zerobounce-go"
"log"
"net/netip"
)
// Example function to show available credits
func credits(api *zerobounce.API) {
response, err := api.GetCredits()
if err != nil {
log.Fatal(fmt.Errorf("unable to fetch the credits: %w", err))
}
if response.IsSuccess() {
fmt.Println("you have", response.Success.Credits, "credits left")
} else if response.IsError() {
fmt.Println("the api returned following error", response.Error.Error)
}
}
// Example function to validate an email address
func validate(api *zerobounce.API, email string, ipAddress *netip.Addr) {
response, err := api.Validate(email, ipAddress)
if err != nil {
log.Fatal(fmt.Errorf("unable to validate email address: %w", err))
}
if response.IsSuccess() {
fmt.Println("the email address", email, "is", response.Success.Status)
} else if response.IsError() {
fmt.Println("the api returned following error", response.Error.Error)
}
}
func main() {
// instantiate the api
api := zerobounce.NewAPI("your-api-key")
// output the result of validation call for a valid email address
validate(api, "[email protected]", nil)
// output the result of validation call for an invalid email address
validate(api, "[email protected]", nil)
// output the result of validation call for an valid email address but for a different IP Address
ipAddress := netip.MustParseAddr("127.0.0.1")
validate(api, "[email protected]", &ipAddress)
// output the result of the get credits call
credits(api)
}
MIT
Set your api key in the ZEROBOUNCE_API_KEY
environment variable, then run:
$ go test ./...
Report here.