Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

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.

Retrieve a bounce

Chilkat Rust Downloads

Rust

// Assumes Chilkat is unlocked. See Global Unlock Sample.
let _ = false;
let http = chilkat::Http::new();
http.set_require_ssl_cert_verify(true);
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.set_auth_token("SENDGRID_API_KEY");
let resp = chilkat::HttpResponse::new();

// SetUrlVar encodes the raw address as a URL component, including the plus sign.
let _ = http.set_url_var("address", "avery+orders@example.com");

if http.http_no_body("GET", "https://api.sendgrid.com/v3/suppression/bounces/{$address}", &resp).is_err() {
    if resp.status_code() == 0 {
        println!("{}", http.last_error_text());
    } else {
        println!("HTTP {}: {}", resp.status_code(), resp.body_str());
    }

    return;
}

if resp.status_code() != 200 {
    println!("HTTP {}: {}", resp.status_code(), resp.body_str());
    return;
}

let rows = chilkat::JsonArray::new();
if rows.load(&resp.body_str()).is_err() {
    println!("Unexpected response: expected JSON.");
    return;
}

if rows.size() == 0 {
    println!("No bounce record for this address.");
    return;
}

let row = chilkat::JsonObject::new();
let mut i = 0;
while i < rows.size() {
    let _ = rows.object_at2(i, &row);
    println!("{}: {} {}", row.string_of("email").unwrap_or_default(), row.string_of("status").unwrap_or_default(), row.string_of("reason").unwrap_or_default());
    i = i + 1;
}