An Email Address can look right but still be wrong and bounce. Real email uses in depths address validation to check if emails really exist without sending any messages.
You can use a Regular Expression to check if an Email Address is formatted correctly.
package main​import ("fmt""regexp")​func main() {pattern := regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-][email protected][a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")email := "[email protected]"matches := pattern.MatchString(email)fmt.Printf("email %v matches the pattern %v", email, matches)}
But these the Email accounts might not actually exist and if you send an Email to them it might bounce.
You can use the Real Email API to do in depth Email Address inspections to check that the address really exists on the email server. In this example we use the go net/http library.
package main​import ("fmt""net/http""io/ioutil""encoding/json""net/url")​type RealEmailResponse struct {Status string `json:"status"`}​func main() {email := "[email protected]"url := "https://isitarealemail.com/api/email/validate?email=" + url.QueryEscape(email)req, _ := http.NewRequest("GET", url, nil)res, err := http.DefaultClient.Do(req)if err != nil {fmt.Println(err)return}​​defer res.Body.Close()body, err := ioutil.ReadAll(res.Body)if err != nil {fmt.Printf("error %v", err)return}var myJson RealEmailResponsejson.Unmarshal(body, &myJson)fmt.Printf("status for %v is %v", email, myJson.Status)}
You will be able to test 100 emails per day, if you have more that that you will need to signup and get an API key. An email might have the status 'unknown' if the email server is unresponsive.
With an API key you will be able to test lots of emails each day.
package main​import ("fmt""net/http""io/ioutil""encoding/json""net/url")​type RealEmailResponse struct {Status string `json:"status"`}​​func main() {email := "[email protected]"apiKey := // todo login to get api key​​url := "https://isitarealemail.com/api/email/validate?email=" + url.QueryEscape(email)​req, _ := http.NewRequest("GET", url, nil)req.Header.Set("Authorization", "bearer " + apiKey)​res, err := http.DefaultClient.Do(req)if err != nil {fmt.Println(err)return}​defer res.Body.Close()body, err := ioutil.ReadAll(res.Body)if err != nil {fmt.Printf("error %v", err)return}if res.StatusCode != 200 {fmt.Printf("unexpected result, check your api key. %v", res.Status)return}var myJson RealEmailResponsejson.Unmarshal(body, &myJson)fmt.Printf("status for %v is %v", email, myJson.Status)}
Depending on your use case you may like to use the bulk csv file validation and read the csv file with go. You can validate a csv file full of emails addresses using the Real Email.
Get started with real email validations today.