Unicode C++
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
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkAuthAwsW.h>
#include <CkSocketW.h>
#include <CkRestW.h>
void ChilkatSample(void)
{
bool 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.
CkJsonObjectW request;
request.UpdateString(L"EmailIdentity",L"sender+reports@example.com");
// 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);
}
rest.AddHeader(L"Content-Type",L"application/json");
const wchar_t *responseText = rest.fullRequestString(L"POST",L"/v2/email/identities",request.emit());
if (rest.get_LastMethodSuccess() != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
if (rest.get_ResponseStatusCode() == 409) {
wprintf(L"This identity already exists in this Region. Check its verification status.\n");
return;
}
if (rest.get_ResponseStatusCode() != 200) {
wprintf(L"SES returned HTTP %d %s\n",rest.get_ResponseStatusCode(),responseText);
return;
}
CkJsonObjectW result;
success = result.Load(responseText);
if (success != true) {
wprintf(L"%s\n",result.lastErrorText());
return;
}
if (result.BoolOf(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");
}
}