Unicode C++
Unicode C++
Amazon SES v2: Send a plain text email
See more Amazon SES Examples
Send a plain text confirmation using a verified sender and credentials with ses:SendEmail. The SES mailbox simulator also works in the sandbox. Other sandbox recipients must be verified. SES permits up to 50 recipients total across To, CC and BCC. Save the returned message ID to correlate later delivery events.
SendEmail · SES sandbox · Sending quotas
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;
// Replace the From address with your verified sender. The destination is the SES mailbox simulator.
CkJsonObjectW request;
request.UpdateString(L"FromEmailAddress",L"sender+reports@example.com");
request.UpdateString(L"Destination.ToAddresses[0]",L"success@simulator.amazonses.com");
request.UpdateString(L"Content.Simple.Subject.Data",L"Report ready");
request.UpdateString(L"Content.Simple.Subject.Charset",L"UTF-8");
request.UpdateString(L"Content.Simple.Body.Text.Data",L"Your weekly report is ready to view.");
request.UpdateString(L"Content.Simple.Body.Text.Charset",L"UTF-8");
// 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/outbound-emails",request.emit());
if (rest.get_LastMethodSuccess() != true) {
wprintf(L"%s\n",rest.lastErrorText());
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.HasMember(L"MessageId") != true) {
wprintf(L"SES returned no message ID.\n");
return;
}
wprintf(L"SES accepted the message. Message ID: %s\n",result.stringOf(L"MessageId"));
}