C# Requires Chilkat v11.0.0+
C#
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 C# Downloads
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
Chilkat.Http http = new Chilkat.Http();
http.RequireSslCertVerify = true;
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY";
Chilkat.HttpResponse resp = new Chilkat.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) {
Debug.WriteLine(http.LastErrorText);
}
else {
Debug.WriteLine("HTTP " + Convert.ToString(resp.StatusCode) + ": " + resp.BodyStr);
}
return;
}
if (resp.StatusCode != 200) {
Debug.WriteLine("HTTP " + Convert.ToString(resp.StatusCode) + ": " + resp.BodyStr);
return;
}
Chilkat.JsonArray rows = new Chilkat.JsonArray();
success = rows.Load(resp.BodyStr);
if (success != true) {
Debug.WriteLine("Unexpected response: expected JSON.");
return;
}
if (rows.Size == 0) {
Debug.WriteLine("No bounce record for this address.");
return;
}
Chilkat.JsonObject row = new Chilkat.JsonObject();
int i = 0;
while ((i < rows.Size)) {
rows.ObjectAt2(i,row);
Debug.WriteLine(row.StringOf("email") + ": " + row.StringOf("status") + " " + row.StringOf("reason"));
i = i + 1;
}