Validate an Email Address in Go

Cloudmersive
1 min readMar 29, 2021

Are you regularly receiving emails from unknown and unverified sources? If so, it’s important to take the proper security measures to ensure the safety of both your organization and users. In the following tutorial, we will detail how to use an API in Go to instantly validate an email address by checking the syntax and checking on the existence of the account by contacting the email server (no emails needed).

To create an instance of the API and call the validation function, we simply need to input the email address and API key into the example code below:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/validate/email/address/full"
method := "POST"
payload := strings.NewReader(`"<string>"`)client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

Process complete! To retrieve your free API key, visit the Cloudmersive website and gain access to 800 calls/month across our library of APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.