Python Requires Chilkat v11.0.0+
Python
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 Python Downloads
import sys
import chilkat2
success = False
# Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
http = chilkat2.Http()
http.RequireSslCertVerify = True
# Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY"
resp = chilkat2.HttpResponse()
# 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):
print(http.LastErrorText)
else:
print("HTTP " + str(resp.StatusCode) + ": " + resp.BodyStr)
sys.exit()
if (resp.StatusCode != 200):
print("HTTP " + str(resp.StatusCode) + ": " + resp.BodyStr)
sys.exit()
rows = chilkat2.JsonArray()
success = rows.Load(resp.BodyStr)
if (success != True):
print("Unexpected response: expected JSON.")
sys.exit()
if (rows.Size == 0):
print("No bounce record for this address.")
sys.exit()
row = chilkat2.JsonObject()
i = 0
while (i < rows.Size) :
rows.ObjectAt2(i,row)
print(row.StringOf("email") + ": " + row.StringOf("status") + " " + row.StringOf("reason"))
i = i + 1