CkJava Requires Chilkat v11.0.0+
CkJava
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 CkJava Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
CkHttp http = new CkHttp();
http.put_RequireSslCertVerify(true);
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.put_AuthToken("SENDGRID_API_KEY");
CkHttpResponse resp = new CkHttpResponse();
// 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.get_StatusCode() == 0) {
System.out.println(http.lastErrorText());
}
else {
System.out.println("HTTP " + resp.get_StatusCode() + ": " + resp.bodyStr());
}
return;
}
if (resp.get_StatusCode() != 200) {
System.out.println("HTTP " + resp.get_StatusCode() + ": " + resp.bodyStr());
return;
}
CkJsonArray rows = new CkJsonArray();
success = rows.Load(resp.bodyStr());
if (success != true) {
System.out.println("Unexpected response: expected JSON.");
return;
}
if (rows.get_Size() == 0) {
System.out.println("No bounce record for this address.");
return;
}
CkJsonObject row = new CkJsonObject();
int i = 0;
while ((i < rows.get_Size())) {
rows.ObjectAt2(i,row);
System.out.println(row.stringOf("email") + ": " + row.stringOf("status") + " " + row.stringOf("reason"));
i = i+1;
}
}
}