Sample code for 30+ languages & platforms
Visual Basic 6.0

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 Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

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

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

Dim signer As New ChilkatAuthAws
'  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 New ChilkatSocket
connection.RequireSslCertVerify = 1
success = connection.Connect(host.GetAsString(),443,1,10000)
If (success <> 1) Then
    Debug.Print connection.LastErrorText
    Exit Sub
End If

Dim rest As New ChilkatRest
success = rest.UseConnection(connection,0)
If (success <> 1) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

success = rest.SetAuthAws(signer)
If (success <> 1) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

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

Dim responseText As String
responseText = rest.FullRequestNoBody("GET",path.GetAsString())
If (rest.LastMethodSuccess <> 1) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

If (rest.ResponseStatusCode = 404) Then
    Debug.Print "No insights found. Check the Region, message ID, and VDM coverage."
    Exit Sub
End If

If (rest.ResponseStatusCode <> 200) Then
    Debug.Print "SES returned HTTP " & rest.ResponseStatusCode & " " & responseText
    Exit Sub
End If

Dim response As New ChilkatJsonObject
success = response.Load(responseText)
If (success <> 1) Then
    Debug.Print response.LastErrorText
    Exit Sub
End If

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

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

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

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