Unicode C
Unicode C
Amazon SES v2: Check regional sending access and quota
See more Amazon SES Examples
Run this in the Region where your application sends mail. Check whether SES accepts sends, whether the account has production access, and how much of its rolling 24-hour quota is in use. Sandbox accounts can send to verified recipients and the mailbox simulator. Sender verification is regional.
GetAccount · Sandbox restrictions
Chilkat Unicode C Downloads
#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 *region;
HCkStringBuilderW host;
HCkAuthAwsW signer;
HCkSocketW connection;
HCkRestW rest;
const wchar_t *sessionToken;
const wchar_t *responseText;
HCkJsonObjectW response;
success = FALSE;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = FALSE;
// 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(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(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(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",L"/v2/email/account");
if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
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(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(host);
CkAuthAwsW_Dispose(signer);
CkSocketW_Dispose(connection);
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(response);
return;
}
wprintf(L"Sending enabled: %d\n",CkJsonObjectW_BoolOf(response,L"SendingEnabled"));
wprintf(L"Production access: %d\n",CkJsonObjectW_BoolOf(response,L"ProductionAccessEnabled"));
wprintf(L"Recipients sent to in the last 24 hours: %s\n",CkJsonObjectW_stringOf(response,L"SendQuota.SentLast24Hours"));
wprintf(L"24-hour recipient quota (-1 means unlimited): %s\n",CkJsonObjectW_stringOf(response,L"SendQuota.Max24HourSend"));
wprintf(L"Maximum recipients per second: %s\n",CkJsonObjectW_stringOf(response,L"SendQuota.MaxSendRate"));
CkStringBuilderW_Dispose(host);
CkAuthAwsW_Dispose(signer);
CkSocketW_Dispose(connection);
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(response);
}