Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL cMessageId
LOCAL oPath
LOCAL cRegion
LOCAL oHost
LOCAL oSigner
LOCAL oConnection
LOCAL oRest
LOCAL cSessionToken
LOCAL cResponseText
LOCAL oResponse
LOCAL i
LOCAL nRecipients
LOCAL j
LOCAL nCount

nSuccess := 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
nSuccess := 0

cMessageId := "YOUR_SES_MESSAGE_ID"
oPath := CreateObject("Chilkat.StringBuilder")
oPath:Append("/v2/email/insights/")
oPath:Append(cMessageId)
oPath:Append("/")
//  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
cRegion := "us-west-2"
oHost := CreateObject("Chilkat.StringBuilder")
oHost:Append("email.")
oHost:Append(cRegion)
oHost:Append(".amazonaws.com")

oSigner := CreateObject("Chilkat.AuthAws")
//  Supply the credentials from your application's credential provider.
oSigner:AccessKey := "AWS_ACCESS_KEY_ID"
oSigner:SecretKey := "AWS_SECRET_ACCESS_KEY"
oSigner:Region := cRegion
oSigner:ServiceName := "ses"

oConnection := CreateObject("Chilkat.Socket")
oConnection:RequireSslCertVerify := 1
nSuccess := oConnection:Connect(oHost:GetAsString(), 443, 1, 10000)
IF (nSuccess != 1)
    ? oConnection:LastErrorText
    oPath:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    RETURN
ENDIF

oRest := CreateObject("Chilkat.Rest")
nSuccess := oRest:UseConnection(oConnection, 0)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oPath:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

nSuccess := oRest:SetAuthAws(oSigner)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oPath:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

//  For temporary AWS credentials, supply the session token from the same provider.
cSessionToken := ""
IF (cSessionToken != "")
    oRest:AddQueryParam("X-Amz-Security-Token", cSessionToken)
ENDIF

cResponseText := oRest:FullRequestNoBody("GET", oPath:GetAsString())
IF (oRest:LastMethodSuccess != 1)
    ? oRest:LastErrorText
    oPath:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

IF (oRest:ResponseStatusCode == 404)
    ? "No insights found. Check the Region, message ID, and VDM coverage."
    oPath:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

IF (oRest:ResponseStatusCode != 200)
    ? "SES returned HTTP " + Str(oRest:ResponseStatusCode) + " " + cResponseText
    oPath:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

oResponse := CreateObject("Chilkat.JsonObject")
nSuccess := oResponse:Load(cResponseText)
IF (nSuccess != 1)
    ? oResponse:LastErrorText
    oPath:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    oResponse:destroy()
    RETURN
ENDIF

i := 0
nRecipients := oResponse:SizeOfArray("Insights")
IF (nRecipients < 1)
    ? "No recipient history is available yet."
ENDIF

DO WHILE (i < nRecipients)
    oResponse:I := i
    ? oResponse:StringOf("Insights[i].Destination")
    j := 0
    nCount := oResponse:SizeOfArray("Insights[i].Events")
    DO WHILE (j < nCount)
        oResponse:J := j
        ? oResponse:StringOf("Insights[i].Events[j].Timestamp") + " " + oResponse:StringOf("Insights[i].Events[j].Type")
        IF (oResponse:HasMember("Insights[i].Events[j].Details.Bounce.DiagnosticCode") == 1)
            ? oResponse:StringOf("Insights[i].Events[j].Details.Bounce.DiagnosticCode")
        ENDIF

        IF (oResponse:HasMember("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType") == 1)
            ? oResponse:StringOf("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType")
        ENDIF

        j := j + 1
    ENDDO
    i := i + 1
ENDDO

oPath:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
oResponse:destroy()