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

Xojo Plugin
Dim success As Boolean
success = False

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
//  Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY"
Dim resp As New Chilkat.HttpResponse

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

success = http.HttpNoBody("GET","https://api.sendgrid.com/v3/suppression/bounces/{$address}",resp)
If (success <> True) Then
    If (resp.StatusCode = 0) Then
        System.DebugLog(http.LastErrorText)
    Else
        System.DebugLog("HTTP " + Str(resp.StatusCode) + ": " + resp.BodyStr)
    End If

    Return
End If

If (resp.StatusCode <> 200) Then
    System.DebugLog("HTTP " + Str(resp.StatusCode) + ": " + resp.BodyStr)
    Return
End If

Dim rows As New Chilkat.JsonArray
success = rows.Load(resp.BodyStr)
If (success <> True) Then
    System.DebugLog("Unexpected response: expected JSON.")
    Return
End If

If (rows.Size = 0) Then
    System.DebugLog("No bounce record for this address.")
    Return
End If

Dim row As New Chilkat.JsonObject
Dim i As Int32
i = 0
While (i < rows.Size)
    success = rows.ObjectAt2(i,row)
    System.DebugLog(row.StringOf("email") + ": " + row.StringOf("status") + " " + row.StringOf("reason"))
    i = i + 1
Wend