C#
C#
Amazon SES v2: Send private appointment reminders and inspect each result
See more Amazon SES Examples
Replace the two recipients with test mailboxes you control. The example supplies an inline template and one private destination per entry. Store each successful message ID against its appointment. Schedule a retry with backoff only for entries with a retryable outcome. Correct permanent errors before resubmission.
SendBulkEmail · Per-entry outcomes
Chilkat C# Downloads
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
Chilkat.JsonObject request = new Chilkat.JsonObject();
request.UpdateString("FromEmailAddress","sender@example.com");
request.UpdateString("DefaultContent.Template.TemplateContent.Subject","Appointment reminder");
request.UpdateString("DefaultContent.Template.TemplateContent.Text","Hello {{name}}, your appointment is {{slot}}.");
request.UpdateString("DefaultContent.Template.TemplateData","{\"name\":\"there\",\"slot\":\"in your booking confirmation\"}");
Chilkat.JsonObject firstReminder = new Chilkat.JsonObject();
firstReminder.UpdateString("name","Avery");
firstReminder.UpdateString("slot","Tuesday at 9 AM Central");
request.UpdateString("BulkEmailEntries[0].Destination.ToAddresses[0]","avery@example.com");
request.UpdateString("BulkEmailEntries[0].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData",firstReminder.Emit());
Chilkat.JsonObject secondReminder = new Chilkat.JsonObject();
secondReminder.UpdateString("name","Robin");
secondReminder.UpdateString("slot","Wednesday at 2 PM Central");
request.UpdateString("BulkEmailEntries[1].Destination.ToAddresses[0]","robin@example.com");
request.UpdateString("BulkEmailEntries[1].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData",secondReminder.Emit());
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
string region = "us-west-2";
Chilkat.StringBuilder host = new Chilkat.StringBuilder();
host.Append("email.");
host.Append(region);
host.Append(".amazonaws.com");
Chilkat.AuthAws signer = new Chilkat.AuthAws();
// Supply the credentials from your application's credential provider.
signer.AccessKey = "AWS_ACCESS_KEY_ID";
signer.SecretKey = "AWS_SECRET_ACCESS_KEY";
signer.Region = region;
signer.ServiceName = "ses";
Chilkat.Socket connection = new Chilkat.Socket();
connection.RequireSslCertVerify = true;
success = connection.Connect(host.GetAsString(),443,true,10000);
if (success != true) {
Debug.WriteLine(connection.LastErrorText);
return;
}
Chilkat.Rest rest = new Chilkat.Rest();
success = rest.UseConnection(connection,false);
if (success != true) {
Debug.WriteLine(rest.LastErrorText);
return;
}
success = rest.SetAuthAws(signer);
if (success != true) {
Debug.WriteLine(rest.LastErrorText);
return;
}
// For temporary AWS credentials, supply the session token from the same provider.
string sessionToken = "";
if (sessionToken != "") {
rest.AddQueryParam("X-Amz-Security-Token",sessionToken);
}
rest.AddHeader("Content-Type","application/json");
string responseText = rest.FullRequestString("POST","/v2/email/outbound-bulk-emails",request.Emit());
if (rest.LastMethodSuccess != true) {
Debug.WriteLine(rest.LastErrorText);
return;
}
if (rest.ResponseStatusCode != 200) {
Debug.WriteLine("SES returned HTTP " + Convert.ToString(rest.ResponseStatusCode) + " " + responseText);
return;
}
Chilkat.JsonObject response = new Chilkat.JsonObject();
success = response.Load(responseText);
if (success != true) {
Debug.WriteLine(response.LastErrorText);
return;
}
int count = response.SizeOfArray("BulkEmailEntryResults");
if (count != request.SizeOfArray("BulkEmailEntries")) {
Debug.WriteLine("Incomplete results. Reconcile the original batch before retrying.");
return;
}
int i = 0;
while ((i < count)) {
response.I = i;
request.I = i;
string recipient = request.StringOf("BulkEmailEntries[i].Destination.ToAddresses[0]");
string status = response.StringOf("BulkEmailEntryResults[i].Status");
if (status == "SUCCESS") {
Debug.WriteLine(recipient + " accepted: " + response.StringOf("BulkEmailEntryResults[i].MessageId"));
}
else {
if ((status == "ACCOUNT_THROTTLED") || (status == "TRANSIENT_FAILURE")) {
Debug.WriteLine(recipient + " retry later: " + status);
}
else {
Debug.WriteLine(recipient + " review before retry: " + status + " " + response.StringOf("BulkEmailEntryResults[i].Error"));
}
}
i = i + 1;
}