Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRequest
LOCAL oFirstReminder
LOCAL oSecondReminder
LOCAL cRegion
LOCAL oHost
LOCAL oSigner
LOCAL oConnection
LOCAL oRest
LOCAL cSessionToken
LOCAL cResponseText
LOCAL oResponse
LOCAL nCount
LOCAL i
LOCAL cRecipient
LOCAL cStatus

nSuccess := 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
nSuccess := 0

oRequest := CreateObject("Chilkat.JsonObject")
oRequest:UpdateString("FromEmailAddress", "sender@example.com")
oRequest:UpdateString("DefaultContent.Template.TemplateContent.Subject", "Appointment reminder")
oRequest:UpdateString("DefaultContent.Template.TemplateContent.Text", "Hello {{name}}, your appointment is {{slot}}.")
oRequest:UpdateString("DefaultContent.Template.TemplateData", '{"name":"there","slot":"in your booking confirmation"}')

oFirstReminder := CreateObject("Chilkat.JsonObject")
oFirstReminder:UpdateString("name", "Avery")
oFirstReminder:UpdateString("slot", "Tuesday at 9 AM Central")
oRequest:UpdateString("BulkEmailEntries[0].Destination.ToAddresses[0]", "avery@example.com")
oRequest:UpdateString("BulkEmailEntries[0].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData", oFirstReminder:Emit())

oSecondReminder := CreateObject("Chilkat.JsonObject")
oSecondReminder:UpdateString("name", "Robin")
oSecondReminder:UpdateString("slot", "Wednesday at 2 PM Central")
oRequest:UpdateString("BulkEmailEntries[1].Destination.ToAddresses[0]", "robin@example.com")
oRequest:UpdateString("BulkEmailEntries[1].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData", oSecondReminder:Emit())
//  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
cRegion := "us-west-2"
oHost := CreateObject("Chilkat.StringBuilder")
oHost:Append("email.")
oHost:Append(cRegion)
oHost:Append(".amazonaws.com")

oSigner := CreateObject("Chilkat.AuthAws")
//  Supply the credentials from your application's credential provider.
oSigner:AccessKey := "AWS_ACCESS_KEY_ID"
oSigner:SecretKey := "AWS_SECRET_ACCESS_KEY"
oSigner:Region := cRegion
oSigner:ServiceName := "ses"

oConnection := CreateObject("Chilkat.Socket")
oConnection:RequireSslCertVerify := 1
nSuccess := oConnection:Connect(oHost:GetAsString(), 443, 1, 10000)
IF (nSuccess != 1)
    ? oConnection:LastErrorText
    oRequest:destroy()
    oFirstReminder:destroy()
    oSecondReminder:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    RETURN
ENDIF

oRest := CreateObject("Chilkat.Rest")
nSuccess := oRest:UseConnection(oConnection, 0)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRequest:destroy()
    oFirstReminder:destroy()
    oSecondReminder:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

nSuccess := oRest:SetAuthAws(oSigner)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRequest:destroy()
    oFirstReminder:destroy()
    oSecondReminder:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

//  For temporary AWS credentials, supply the session token from the same provider.
cSessionToken := ""
IF (cSessionToken != "")
    oRest:AddQueryParam("X-Amz-Security-Token", cSessionToken)
ENDIF

oRest:AddHeader("Content-Type", "application/json")
cResponseText := oRest:FullRequestString("POST", "/v2/email/outbound-bulk-emails", oRequest:Emit())
IF (oRest:LastMethodSuccess != 1)
    ? oRest:LastErrorText
    oRequest:destroy()
    oFirstReminder:destroy()
    oSecondReminder:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

IF (oRest:ResponseStatusCode != 200)
    ? "SES returned HTTP " + Str(oRest:ResponseStatusCode) + " " + cResponseText
    oRequest:destroy()
    oFirstReminder:destroy()
    oSecondReminder:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    RETURN
ENDIF

oResponse := CreateObject("Chilkat.JsonObject")
nSuccess := oResponse:Load(cResponseText)
IF (nSuccess != 1)
    ? oResponse:LastErrorText
    oRequest:destroy()
    oFirstReminder:destroy()
    oSecondReminder:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    oResponse:destroy()
    RETURN
ENDIF

nCount := oResponse:SizeOfArray("BulkEmailEntryResults")
IF (nCount != oRequest:SizeOfArray("BulkEmailEntries"))
    ? "Incomplete results. Reconcile the original batch before retrying."
    oRequest:destroy()
    oFirstReminder:destroy()
    oSecondReminder:destroy()
    oHost:destroy()
    oSigner:destroy()
    oConnection:destroy()
    oRest:destroy()
    oResponse:destroy()
    RETURN
ENDIF

i := 0
DO WHILE (i < nCount)
    oResponse:I := i
    oRequest:I := i
    cRecipient := oRequest:StringOf("BulkEmailEntries[i].Destination.ToAddresses[0]")
    cStatus := oResponse:StringOf("BulkEmailEntryResults[i].Status")
    IF (cStatus == "SUCCESS")
        ? cRecipient + " accepted: " + oResponse:StringOf("BulkEmailEntryResults[i].MessageId")
    ELSE
        IF ((cStatus == "ACCOUNT_THROTTLED") .OR. (cStatus == "TRANSIENT_FAILURE"))
            ? cRecipient + " retry later: " + cStatus
        ELSE
            ? cRecipient + " review before retry: " + cStatus + " " + oResponse:StringOf("BulkEmailEntryResults[i].Error")
        ENDIF

    ENDIF

    i := i + 1
ENDDO

oRequest:destroy()
oFirstReminder:destroy()
oSecondReminder:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
oResponse:destroy()