Sample code for 30+ languages & platforms
Unicode C++

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 Unicode C++ Downloads

Unicode C++
#include <CkStringBuilderW.h>
#include <CkAuthAwsW.h>
#include <CkSocketW.h>
#include <CkRestW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    const wchar_t *messageId = L"YOUR_SES_MESSAGE_ID";
    CkStringBuilderW path;
    path.Append(L"/v2/email/insights/");
    path.Append(messageId);
    path.Append(L"/");
    //  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
    const wchar_t *region = L"us-west-2";
    CkStringBuilderW host;
    host.Append(L"email.");
    host.Append(region);
    host.Append(L".amazonaws.com");

    CkAuthAwsW signer;
    //  Supply the credentials from your application's credential provider.
    signer.put_AccessKey(L"AWS_ACCESS_KEY_ID");
    signer.put_SecretKey(L"AWS_SECRET_ACCESS_KEY");
    signer.put_Region(region);
    signer.put_ServiceName(L"ses");

    CkSocketW connection;
    connection.put_RequireSslCertVerify(true);
    success = connection.Connect(host.getAsString(),443,true,10000);
    if (success != true) {
        wprintf(L"%s\n",connection.lastErrorText());
        return;
    }

    CkRestW rest;
    success = rest.UseConnection(connection,false);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    success = rest.SetAuthAws(signer);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

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

    const wchar_t *responseText = rest.fullRequestNoBody(L"GET",path.getAsString());
    if (rest.get_LastMethodSuccess() != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    if (rest.get_ResponseStatusCode() == 404) {
        wprintf(L"No insights found. Check the Region, message ID, and VDM coverage.\n");
        return;
    }

    if (rest.get_ResponseStatusCode() != 200) {
        wprintf(L"SES returned HTTP %d %s\n",rest.get_ResponseStatusCode(),responseText);
        return;
    }

    CkJsonObjectW response;
    success = response.Load(responseText);
    if (success != true) {
        wprintf(L"%s\n",response.lastErrorText());
        return;
    }

    int i = 0;
    int recipients = response.SizeOfArray(L"Insights");
    if (recipients < 1) {
        wprintf(L"No recipient history is available yet.\n");
    }

    while ((i < recipients)) {
        response.put_I(i);
        wprintf(L"%s\n",response.stringOf(L"Insights[i].Destination"));
        int j = 0;
        int count = response.SizeOfArray(L"Insights[i].Events");
        while ((j < count)) {
            response.put_J(j);
            wprintf(L"%s %s\n",response.stringOf(L"Insights[i].Events[j].Timestamp"),response.stringOf(L"Insights[i].Events[j].Type"));
            if (response.HasMember(L"Insights[i].Events[j].Details.Bounce.DiagnosticCode") == true) {
                wprintf(L"%s\n",response.stringOf(L"Insights[i].Events[j].Details.Bounce.DiagnosticCode"));
            }

            if (response.HasMember(L"Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType") == true) {
                wprintf(L"%s\n",response.stringOf(L"Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType"));
            }

            j = j + 1;
        }

        i = i + 1;
    }
    }