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 <C_CkStringBuilderW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkSocketW.h>
#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    const wchar_t *messageId;
    HCkStringBuilderW path;
    const wchar_t *region;
    HCkStringBuilderW host;
    HCkAuthAwsW signer;
    HCkSocketW connection;
    HCkRestW rest;
    const wchar_t *sessionToken;
    const wchar_t *responseText;
    HCkJsonObjectW response;
    int i;
    int recipients;
    int j;
    int count;

    success = FALSE;

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

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

    signer = CkAuthAwsW_Create();
    //  Supply the credentials from your application's credential provider.
    CkAuthAwsW_putAccessKey(signer,L"AWS_ACCESS_KEY_ID");
    CkAuthAwsW_putSecretKey(signer,L"AWS_SECRET_ACCESS_KEY");
    CkAuthAwsW_putRegion(signer,region);
    CkAuthAwsW_putServiceName(signer,L"ses");

    connection = CkSocketW_Create();
    CkSocketW_putRequireSslCertVerify(connection,TRUE);
    success = CkSocketW_Connect(connection,CkStringBuilderW_getAsString(host),443,TRUE,10000);
    if (success != TRUE) {
        wprintf(L"%s\n",CkSocketW_lastErrorText(connection));
        CkStringBuilderW_Dispose(path);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        return;
    }

    rest = CkRestW_Create();
    success = CkRestW_UseConnection(rest,connection,FALSE);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkStringBuilderW_Dispose(path);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        return;
    }

    success = CkRestW_SetAuthAws(rest,signer);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkStringBuilderW_Dispose(path);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        return;
    }

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

    responseText = CkRestW_fullRequestNoBody(rest,L"GET",CkStringBuilderW_getAsString(path));
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkStringBuilderW_Dispose(path);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) == 404) {
        wprintf(L"No insights found. Check the Region, message ID, and VDM coverage.\n");
        CkStringBuilderW_Dispose(path);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) != 200) {
        wprintf(L"SES returned HTTP %d %s\n",CkRestW_getResponseStatusCode(rest),responseText);
        CkStringBuilderW_Dispose(path);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        return;
    }

    response = CkJsonObjectW_Create();
    success = CkJsonObjectW_Load(response,responseText);
    if (success != TRUE) {
        wprintf(L"%s\n",CkJsonObjectW_lastErrorText(response));
        CkStringBuilderW_Dispose(path);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(response);
        return;
    }

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

    while ((i < recipients)) {
        CkJsonObjectW_putI(response,i);
        wprintf(L"%s\n",CkJsonObjectW_stringOf(response,L"Insights[i].Destination"));
        j = 0;
        count = CkJsonObjectW_SizeOfArray(response,L"Insights[i].Events");
        while ((j < count)) {
            CkJsonObjectW_putJ(response,j);
            wprintf(L"%s %s\n",CkJsonObjectW_stringOf(response,L"Insights[i].Events[j].Timestamp"),CkJsonObjectW_stringOf(response,L"Insights[i].Events[j].Type"));
            if (CkJsonObjectW_HasMember(response,L"Insights[i].Events[j].Details.Bounce.DiagnosticCode") == TRUE) {
                wprintf(L"%s\n",CkJsonObjectW_stringOf(response,L"Insights[i].Events[j].Details.Bounce.DiagnosticCode"));
            }

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

            j = j + 1;
        }

        i = i + 1;
    }



    CkStringBuilderW_Dispose(path);
    CkStringBuilderW_Dispose(host);
    CkAuthAwsW_Dispose(signer);
    CkSocketW_Dispose(connection);
    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(response);

    }