Go Requires Chilkat v11.0.0+
Go
SendGrid: Look up a bounced email address
See more SendGrid Examples
Look up a recipient on the bounce suppression list without changing it. SendGrid returns an array. An empty array means there is no bounce record for this lookup; it does not prove a particular message reached the inbox.
Chilkat Go Downloads
success := false
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false
http := chilkat.NewHttp()
http.SetRequireSslCertVerify(true)
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.SetAuthToken("SENDGRID_API_KEY")
resp := chilkat.NewHttpResponse()
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
http.SetUrlVar("address","avery+orders@example.com")
success = http.HttpNoBody("GET","https://api.sendgrid.com/v3/suppression/bounces/{$address}",resp)
if success != true {
if resp.StatusCode() == 0 {
fmt.Println(http.LastErrorText())
} else {
fmt.Println("HTTP ", resp.StatusCode(), ": ", resp.BodyStr())
}
http.DisposeHttp()
resp.DisposeHttpResponse()
return
}
if resp.StatusCode() != 200 {
fmt.Println("HTTP ", resp.StatusCode(), ": ", resp.BodyStr())
http.DisposeHttp()
resp.DisposeHttpResponse()
return
}
rows := chilkat.NewJsonArray()
success = rows.Load(resp.BodyStr())
if success != true {
fmt.Println("Unexpected response: expected JSON.")
http.DisposeHttp()
resp.DisposeHttpResponse()
rows.DisposeJsonArray()
return
}
if rows.Size() == 0 {
fmt.Println("No bounce record for this address.")
http.DisposeHttp()
resp.DisposeHttpResponse()
rows.DisposeJsonArray()
return
}
row := chilkat.NewJsonObject()
i := 0
for (i < rows.Size()) {
rows.ObjectAt2(i,row)
fmt.Println(*row.StringOf("email"), ": ", *row.StringOf("status"), " ", *row.StringOf("reason"))
i = i + 1
}
http.DisposeHttp()
resp.DisposeHttpResponse()
rows.DisposeJsonArray()
row.DisposeJsonObject()