Sample code for 30+ languages & platforms
Unicode C

Amazon SES v2: Request verification of a sender email address

See more Amazon SES Examples

Create an email identity in the AWS Region where the application sends mail. Use a mailbox you control and credentials with ses:CreateEmailIdentity. SES emails a verification link that expires after 24 hours. After following it, run Check sender verification status in the same Region.

CreateEmailIdentity · Verify an email identity

Chilkat Unicode C Downloads

Unicode C
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkSocketW.h>
#include <C_CkRestW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJsonObjectW request;
    const wchar_t *region;
    HCkStringBuilderW host;
    HCkAuthAwsW signer;
    HCkSocketW connection;
    HCkRestW rest;
    const wchar_t *sessionToken;
    const wchar_t *responseText;
    HCkJsonObjectW result;

    success = FALSE;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    success = FALSE;

    //  Use an address whose inbox you can open. SES sends the verification link there.
    request = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(request,L"EmailIdentity",L"sender+reports@example.com");

    //  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));
        CkJsonObjectW_Dispose(request);
        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));
        CkJsonObjectW_Dispose(request);
        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));
        CkJsonObjectW_Dispose(request);
        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);
    }

    CkRestW_AddHeader(rest,L"Content-Type",L"application/json");
    responseText = CkRestW_fullRequestString(rest,L"POST",L"/v2/email/identities",CkJsonObjectW_emit(request));
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkJsonObjectW_Dispose(request);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) == 409) {
        wprintf(L"This identity already exists in this Region. Check its verification status.\n");
        CkJsonObjectW_Dispose(request);
        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);
        CkJsonObjectW_Dispose(request);
        CkStringBuilderW_Dispose(host);
        CkAuthAwsW_Dispose(signer);
        CkSocketW_Dispose(connection);
        CkRestW_Dispose(rest);
        return;
    }

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

    if (CkJsonObjectW_BoolOf(result,L"VerifiedForSendingStatus") == TRUE) {
        wprintf(L"The identity is already verified for sending.\n");
    }
    else {
        wprintf(L"Open the verification email from AWS, follow its link, then check the identity status.\n");
    }



    CkJsonObjectW_Dispose(request);
    CkStringBuilderW_Dispose(host);
    CkAuthAwsW_Dispose(signer);
    CkSocketW_Dispose(connection);
    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(result);

    }