Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
string ls_MessageId
oleobject loo_Path
string ls_Region
oleobject loo_Host
oleobject loo_Signer
oleobject loo_Connection
oleobject loo_Rest
string ls_SessionToken
string ls_ResponseText
oleobject loo_Response
long i
long li_Recipients
long j
long li_Count

li_Success = 0

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

ls_MessageId = "YOUR_SES_MESSAGE_ID"
loo_Path = create oleobject
li_rc = loo_Path.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_Path
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Path.Append("/v2/email/insights/")
loo_Path.Append(ls_MessageId)
loo_Path.Append("/")
//  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
ls_Region = "us-west-2"
loo_Host = create oleobject
li_rc = loo_Host.ConnectToNewObject("Chilkat.StringBuilder")

loo_Host.Append("email.")
loo_Host.Append(ls_Region)
loo_Host.Append(".amazonaws.com")

loo_Signer = create oleobject
li_rc = loo_Signer.ConnectToNewObject("Chilkat.AuthAws")

//  Supply the credentials from your application's credential provider.
loo_Signer.AccessKey = "AWS_ACCESS_KEY_ID"
loo_Signer.SecretKey = "AWS_SECRET_ACCESS_KEY"
loo_Signer.Region = ls_Region
loo_Signer.ServiceName = "ses"

loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")

loo_Connection.RequireSslCertVerify = 1
li_Success = loo_Connection.Connect(loo_Host.GetAsString(),443,1,10000)
if li_Success <> 1 then
    Write-Debug loo_Connection.LastErrorText
    destroy loo_Path
    destroy loo_Host
    destroy loo_Signer
    destroy loo_Connection
    return
end if

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

li_Success = loo_Rest.UseConnection(loo_Connection,0)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Path
    destroy loo_Host
    destroy loo_Signer
    destroy loo_Connection
    destroy loo_Rest
    return
end if

li_Success = loo_Rest.SetAuthAws(loo_Signer)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Path
    destroy loo_Host
    destroy loo_Signer
    destroy loo_Connection
    destroy loo_Rest
    return
end if

//  For temporary AWS credentials, supply the session token from the same provider.
ls_SessionToken = ""
if ls_SessionToken <> "" then
    loo_Rest.AddQueryParam("X-Amz-Security-Token",ls_SessionToken)
end if

ls_ResponseText = loo_Rest.FullRequestNoBody("GET",loo_Path.GetAsString())
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Path
    destroy loo_Host
    destroy loo_Signer
    destroy loo_Connection
    destroy loo_Rest
    return
end if

if loo_Rest.ResponseStatusCode = 404 then
    Write-Debug "No insights found. Check the Region, message ID, and VDM coverage."
    destroy loo_Path
    destroy loo_Host
    destroy loo_Signer
    destroy loo_Connection
    destroy loo_Rest
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "SES returned HTTP " + string(loo_Rest.ResponseStatusCode) + " " + ls_ResponseText
    destroy loo_Path
    destroy loo_Host
    destroy loo_Signer
    destroy loo_Connection
    destroy loo_Rest
    return
end if

loo_Response = create oleobject
li_rc = loo_Response.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_Response.Load(ls_ResponseText)
if li_Success <> 1 then
    Write-Debug loo_Response.LastErrorText
    destroy loo_Path
    destroy loo_Host
    destroy loo_Signer
    destroy loo_Connection
    destroy loo_Rest
    destroy loo_Response
    return
end if

i = 0
li_Recipients = loo_Response.SizeOfArray("Insights")
if li_Recipients < 1 then
    Write-Debug "No recipient history is available yet."
end if

do while (i < li_Recipients)
    loo_Response.I = i
    Write-Debug loo_Response.StringOf("Insights[i].Destination")
    j = 0
    li_Count = loo_Response.SizeOfArray("Insights[i].Events")
    do while (j < li_Count)
        loo_Response.J = j
        Write-Debug loo_Response.StringOf("Insights[i].Events[j].Timestamp") + " " + loo_Response.StringOf("Insights[i].Events[j].Type")
        if loo_Response.HasMember("Insights[i].Events[j].Details.Bounce.DiagnosticCode") = 1 then
            Write-Debug loo_Response.StringOf("Insights[i].Events[j].Details.Bounce.DiagnosticCode")
        end if

        if loo_Response.HasMember("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType") = 1 then
            Write-Debug loo_Response.StringOf("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType")
        end if

        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Path
destroy loo_Host
destroy loo_Signer
destroy loo_Connection
destroy loo_Rest
destroy loo_Response