Delphi DLL Requires Chilkat v11.0.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
http: HCkHttp;
resp: HCkHttpResponse;
rows: HCkJsonArray;
row: HCkJsonObject;
i: Integer;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success := False;
http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
CkHttp_putAuthToken(http,'SENDGRID_API_KEY');
resp := CkHttpResponse_Create();
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
CkHttp_SetUrlVar(http,'address','avery+orders@example.com');
success := CkHttp_HttpNoBody(http,'GET','https://api.sendgrid.com/v3/suppression/bounces/{$address}',resp);
if (success <> True) then
begin
if (CkHttpResponse_getStatusCode(resp) = 0) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
end
else
begin
Memo1.Lines.Add('HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)) + ': ' + CkHttpResponse__bodyStr(resp));
end;
Exit;
end;
if (CkHttpResponse_getStatusCode(resp) <> 200) then
begin
Memo1.Lines.Add('HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)) + ': ' + CkHttpResponse__bodyStr(resp));
Exit;
end;
rows := CkJsonArray_Create();
success := CkJsonArray_Load(rows,CkHttpResponse__bodyStr(resp));
if (success <> True) then
begin
Memo1.Lines.Add('Unexpected response: expected JSON.');
Exit;
end;
if (CkJsonArray_getSize(rows) = 0) then
begin
Memo1.Lines.Add('No bounce record for this address.');
Exit;
end;
row := CkJsonObject_Create();
i := 0;
while (i < CkJsonArray_getSize(rows)) do
begin
CkJsonArray_ObjectAt2(rows,i,row);
Memo1.Lines.Add(CkJsonObject__stringOf(row,'email') + ': ' + CkJsonObject__stringOf(row,'status') + ' ' + CkJsonObject__stringOf(row,'reason'));
i := i + 1;
end;
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkJsonArray_Dispose(rows);
CkJsonObject_Dispose(row);