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

Delphi ActiveX
var
success: Integer;
http: TChilkatHttp;
resp: TChilkatHttpResponse;
rows: TChilkatJsonArray;
row: TChilkatJsonObject;
i: Integer;

begin
success := 0;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
success := 0;
http := TChilkatHttp.Create(Self);
http.RequireSslCertVerify := 1;
//  Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken := 'SENDGRID_API_KEY';
resp := TChilkatHttpResponse.Create(Self);

//  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.ControlInterface);
if (success <> 1) then
  begin
    if (resp.StatusCode = 0) then
      begin
        Memo1.Lines.Add(http.LastErrorText);
      end
    else
      begin
        Memo1.Lines.Add('HTTP ' + IntToStr(resp.StatusCode) + ': ' + resp.BodyStr);
      end;
    Exit;
  end;
if (resp.StatusCode <> 200) then
  begin
    Memo1.Lines.Add('HTTP ' + IntToStr(resp.StatusCode) + ': ' + resp.BodyStr);
    Exit;
  end;

rows := TChilkatJsonArray.Create(Self);
success := rows.Load(resp.BodyStr);
if (success <> 1) then
  begin
    Memo1.Lines.Add('Unexpected response: expected JSON.');
    Exit;
  end;
if (rows.Size = 0) then
  begin
    Memo1.Lines.Add('No bounce record for this address.');
    Exit;
  end;
row := TChilkatJsonObject.Create(Self);
i := 0;
while (i < rows.Size) do
  begin
    rows.ObjectAt2(i,row.ControlInterface);
    Memo1.Lines.Add(row.StringOf('email') + ': ' + row.StringOf('status') + ' ' + row.StringOf('reason'));
    i := i + 1;
  end;