Using an API for email verification involves sending a GET request to the API endpoint. Here's how you can do this using Go:
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Response struct {
IsValid bool `json:"IsValid"`
Score int `json:"Score"`
Email string `json:"Email"`
State string `json:"State"`
Reason string `json:"Reason"`
Domain string `json:"Domain"`
Free bool `json:"Free"`
Role bool `json:"Role"`
Disposable bool `json:"Disposable"`
AcceptAll bool `json:"AcceptAll"`
Tag bool `json:"Tag"`
MXRecord string `json:"MXRecord"`
EmailAdditionalInfo []struct {
Key string `json:"Key"`
Value string `json:"Value"`
} `json:"EmailAdditionalInfo"`
}
func main() {
email := "Email_Address" // Replace with the email you want to verify
token := "YOUR_API_KEY" // Replace with your actual API key
url := fmt.Sprintf("https://api.ValidEmail.net/?email=%s&token=%s", email, token)
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var data Response
json.Unmarshal(body, &data)
fmt.Println("Email is valid:", data.IsValid)
fmt.Println("Score:", data.Score)
fmt.Println("Email state:", data.State)
fmt.Println("Reason:", data.Reason)
for _, info := range data.EmailAdditionalInfo {
fmt.Println(info.Key+":", info.Value)
}
}
Remember to replace 'Email_Address' and 'YOUR_API_KEY' with the actual email address you want to verify and your actual API key.