Sample code for 30+ languages & platforms
Go

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

Go
    success := false

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    success = false

    messageId := "YOUR_SES_MESSAGE_ID"
    path := chilkat.NewStringBuilder()
    path.Append("/v2/email/insights/")
    path.Append(messageId)
    path.Append("/")
    //  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
    region := "us-west-2"
    host := chilkat.NewStringBuilder()
    host.Append("email.")
    host.Append(region)
    host.Append(".amazonaws.com")

    signer := chilkat.NewAuthAws()
    //  Supply the credentials from your application's credential provider.
    signer.SetAccessKey("AWS_ACCESS_KEY_ID")
    signer.SetSecretKey("AWS_SECRET_ACCESS_KEY")
    signer.SetRegion(region)
    signer.SetServiceName("ses")

    connection := chilkat.NewSocket()
    connection.SetRequireSslCertVerify(true)
    success = connection.Connect(*host.GetAsString(),443,true,10000)
    if success != true {
        fmt.Println(connection.LastErrorText())
        path.DisposeStringBuilder()
        host.DisposeStringBuilder()
        signer.DisposeAuthAws()
        connection.DisposeSocket()
        return
    }

    rest := chilkat.NewRest()
    success = rest.UseConnection(connection,false)
    if success != true {
        fmt.Println(rest.LastErrorText())
        path.DisposeStringBuilder()
        host.DisposeStringBuilder()
        signer.DisposeAuthAws()
        connection.DisposeSocket()
        rest.DisposeRest()
        return
    }

    success = rest.SetAuthAws(signer)
    if success != true {
        fmt.Println(rest.LastErrorText())
        path.DisposeStringBuilder()
        host.DisposeStringBuilder()
        signer.DisposeAuthAws()
        connection.DisposeSocket()
        rest.DisposeRest()
        return
    }

    //  For temporary AWS credentials, supply the session token from the same provider.
    sessionToken := ""
    if sessionToken != "" {
        rest.AddQueryParam("X-Amz-Security-Token",sessionToken)
    }

    responseText := rest.FullRequestNoBody("GET",*path.GetAsString())
    if rest.LastMethodSuccess() != true {
        fmt.Println(rest.LastErrorText())
        path.DisposeStringBuilder()
        host.DisposeStringBuilder()
        signer.DisposeAuthAws()
        connection.DisposeSocket()
        rest.DisposeRest()
        return
    }

    if rest.ResponseStatusCode() == 404 {
        fmt.Println("No insights found. Check the Region, message ID, and VDM coverage.")
        path.DisposeStringBuilder()
        host.DisposeStringBuilder()
        signer.DisposeAuthAws()
        connection.DisposeSocket()
        rest.DisposeRest()
        return
    }

    if rest.ResponseStatusCode() != 200 {
        fmt.Println("SES returned HTTP ", rest.ResponseStatusCode(), " ", *responseText)
        path.DisposeStringBuilder()
        host.DisposeStringBuilder()
        signer.DisposeAuthAws()
        connection.DisposeSocket()
        rest.DisposeRest()
        return
    }

    response := chilkat.NewJsonObject()
    success = response.Load(*responseText)
    if success != true {
        fmt.Println(response.LastErrorText())
        path.DisposeStringBuilder()
        host.DisposeStringBuilder()
        signer.DisposeAuthAws()
        connection.DisposeSocket()
        rest.DisposeRest()
        response.DisposeJsonObject()
        return
    }

    i := 0
    recipients := response.SizeOfArray("Insights")
    if recipients < 1 {
        fmt.Println("No recipient history is available yet.")
    }

    for (i < recipients) {
        response.SetI(i)
        fmt.Println(*response.StringOf("Insights[i].Destination"))
        j := 0
        count := response.SizeOfArray("Insights[i].Events")
        for (j < count) {
            response.SetJ(j)
            fmt.Println(*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 {
                fmt.Println(*response.StringOf("Insights[i].Events[j].Details.Bounce.DiagnosticCode"))
            }

            if response.HasMember("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType") == true {
                fmt.Println(*response.StringOf("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType"))
            }

            j = j + 1
        }

        i = i + 1
    }


    path.DisposeStringBuilder()
    host.DisposeStringBuilder()
    signer.DisposeAuthAws()
    connection.DisposeSocket()
    rest.DisposeRest()
    response.DisposeJsonObject()