Lua Requires Chilkat v11.0.0+
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local success = false
local http = chilkat.Http.new()
http.require_ssl_cert_verify = true
-- Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.auth_token = "SENDGRID_API_KEY"
local resp = chilkat.HttpResponse.new()
-- SetUrlVar encodes the raw address as a URL component, including the plus sign.
http:set_url_var("address", "avery+orders@example.com")
success = http:http_no_body("GET", "https://api.sendgrid.com/v3/suppression/bounces/{$address}", resp)
if not success then
if resp.status_code == 0 then
print(http.last_error_text)
else
print("HTTP " .. resp.status_code .. ": " .. resp.body_str)
end
return
end
if resp.status_code ~= 200 then
print("HTTP " .. resp.status_code .. ": " .. resp.body_str)
return
end
local rows = chilkat.JsonArray.new()
success = rows:load(resp.body_str)
if not success then
print("Unexpected response: expected JSON.")
return
end
if rows.size == 0 then
print("No bounce record for this address.")
return
end
local row = chilkat.JsonObject.new()
local i = 0
while i < rows.size do
rows:object_at2(i, row)
print(row:string_of("email") .. ": " .. row:string_of("status") .. " " .. row:string_of("reason"))
i = i + 1
end