Sample code for 30+ languages & platforms
Android™ 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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    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) {
            Log.i(TAG, http.lastErrorText());
            }
        else {
            Log.i(TAG, "HTTP " + String.valueOf(resp.get_StatusCode()) + ": " + resp.bodyStr());
            }

        return;
        }

    if (resp.get_StatusCode() != 200) {
        Log.i(TAG, "HTTP " + String.valueOf(resp.get_StatusCode()) + ": " + resp.bodyStr());
        return;
        }

    CkJsonArray rows = new CkJsonArray();
    success = rows.Load(resp.bodyStr());
    if (success != true) {
        Log.i(TAG, "Unexpected response: expected JSON.");
        return;
        }

    if (rows.get_Size() == 0) {
        Log.i(TAG, "No bounce record for this address.");
        return;
        }

    CkJsonObject row = new CkJsonObject();
    int i = 0;
    while ((i < rows.get_Size())) {
        rows.ObjectAt2(i,row);
        Log.i(TAG, row.stringOf("email") + ": " + row.stringOf("status") + " " + row.stringOf("reason"));
        i = i + 1;
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}