Sample code for 30+ languages & platforms
B4X

Amazon SES v2: Look up delivery history for a message ID

See more Amazon SES Examples

Enable Virtual Deliverability Manager for the sending account. Use the SES MessageId from a recent eligible send to a real test mailbox in the same Region. Mailbox simulator sends are excluded from VDM. Events are grouped by destination. Timestamps in the REST response are Unix epoch seconds.

GetMessageInsights · VDM dashboard

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False

Dim messageId As String = "YOUR_SES_MESSAGE_ID"
Dim path As ChilkatStringBuilder
path.Initialize
path.Append("/v2/email/insights/")
path.Append(messageId)
path.Append("/")
'  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
Dim region As String = "us-west-2"
Dim host As ChilkatStringBuilder
host.Initialize
host.Append("email.")
host.Append(region)
host.Append(".amazonaws.com")

Dim signer As ChilkatAuthAws
signer.Initialize
'  Supply the credentials from your application's credential provider.
signer.AccessKey = "AWS_ACCESS_KEY_ID"
signer.SecretKey = "AWS_SECRET_ACCESS_KEY"
signer.Region = region
signer.ServiceName = "ses"

Dim connection As ChilkatSocket
connection.Initialize("connection")
connection.RequireSslCertVerify = True
success = connection.Connect(host.GetAsString, 443, True, 10000)
If success <> True Then
    Log(connection.LastErrorText)
    Return
End If


Dim rest As ChilkatRest
rest.Initialize("rest")
success = rest.UseConnection(connection, False)
If success <> True Then
    Log(rest.LastErrorText)
    Return
End If

success = rest.SetAuthAws(signer)
If success <> True Then
    Log(rest.LastErrorText)
    Return
End If

'  For temporary AWS credentials, supply the session token from the same provider.
Dim sessionToken As String = ""
If sessionToken <> "" Then
    rest.AddQueryParam("X-Amz-Security-Token", sessionToken)
End If


Dim responseText As String = rest.FullRequestNoBody("GET", path.GetAsString)
If rest.LastMethodSuccess <> True Then
    Log(rest.LastErrorText)
    Return
End If

If rest.ResponseStatusCode = 404 Then
    Log("No insights found. Check the Region, message ID, and VDM coverage.")
    Return
End If

If rest.ResponseStatusCode <> 200 Then
    Log("SES returned HTTP " & rest.ResponseStatusCode & " " & responseText)
    Return
End If

Dim response As ChilkatJsonObject
response.Initialize
success = response.Load(responseText)
If success <> True Then
    Log(response.LastErrorText)
    Return
End If

Dim i As Int = 0
Dim recipients As Int = response.SizeOfArray("Insights")
If recipients < 1 Then
    Log("No recipient history is available yet.")
End If

Do While (i < recipients)
    response.I = i
    Log(response.StringOf("Insights[i].Destination"))
    Dim j As Int = 0
    Dim count As Int = response.SizeOfArray("Insights[i].Events")
    Do While (j < count)
        response.J = j
        Log(response.StringOf("Insights[i].Events[j].Timestamp") & " " & response.StringOf("Insights[i].Events[j].Type"))
        If response.HasMember("Insights[i].Events[j].Details.Bounce.DiagnosticCode") = True Then
            Log(response.StringOf("Insights[i].Events[j].Details.Bounce.DiagnosticCode"))
        End If

        If response.HasMember("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType") = True Then
            Log(response.StringOf("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType"))
        End If

        j = j + 1
    Loop
    i = i + 1
Loop