Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRequest
LOCAL loFirstReminder
LOCAL loSecondReminder
LOCAL lcRegion
LOCAL loHost
LOCAL loSigner
LOCAL loConnection
LOCAL loRest
LOCAL lcSessionToken
LOCAL lcResponseText
LOCAL loResponse
LOCAL lnCount
LOCAL i
LOCAL lcRecipient
LOCAL lcStatus
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
loRequest = CreateObject('Chilkat.JsonObject')
loRequest.UpdateString("FromEmailAddress","sender@example.com")
loRequest.UpdateString("DefaultContent.Template.TemplateContent.Subject","Appointment reminder")
loRequest.UpdateString("DefaultContent.Template.TemplateContent.Text","Hello {{name}}, your appointment is {{slot}}.")
loRequest.UpdateString("DefaultContent.Template.TemplateData",'{"name":"there","slot":"in your booking confirmation"}')
loFirstReminder = CreateObject('Chilkat.JsonObject')
loFirstReminder.UpdateString("name","Avery")
loFirstReminder.UpdateString("slot","Tuesday at 9 AM Central")
loRequest.UpdateString("BulkEmailEntries[0].Destination.ToAddresses[0]","avery@example.com")
loRequest.UpdateString("BulkEmailEntries[0].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData",loFirstReminder.Emit())
loSecondReminder = CreateObject('Chilkat.JsonObject')
loSecondReminder.UpdateString("name","Robin")
loSecondReminder.UpdateString("slot","Wednesday at 2 PM Central")
loRequest.UpdateString("BulkEmailEntries[1].Destination.ToAddresses[0]","robin@example.com")
loRequest.UpdateString("BulkEmailEntries[1].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData",loSecondReminder.Emit())
* Use the same AWS Region for the identity, endpoint, and Signature Version 4.
lcRegion = "us-west-2"
loHost = CreateObject('Chilkat.StringBuilder')
loHost.Append("email.")
loHost.Append(lcRegion)
loHost.Append(".amazonaws.com")
loSigner = CreateObject('Chilkat.AuthAws')
* Supply the credentials from your application's credential provider.
loSigner.AccessKey = "AWS_ACCESS_KEY_ID"
loSigner.SecretKey = "AWS_SECRET_ACCESS_KEY"
loSigner.Region = lcRegion
loSigner.ServiceName = "ses"
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
lnSuccess = loConnection.Connect(loHost.GetAsString(),443,1,10000)
IF (lnSuccess <> 1) THEN
? loConnection.LastErrorText
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
CANCEL
ENDIF
loRest = CreateObject('Chilkat.Rest')
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
CANCEL
ENDIF
lnSuccess = loRest.SetAuthAws(loSigner)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
CANCEL
ENDIF
* For temporary AWS credentials, supply the session token from the same provider.
lcSessionToken = ""
IF (lcSessionToken <> "") THEN
loRest.AddQueryParam("X-Amz-Security-Token",lcSessionToken)
ENDIF
loRest.AddHeader("Content-Type","application/json")
lcResponseText = loRest.FullRequestString("POST","/v2/email/outbound-bulk-emails",loRequest.Emit())
IF (loRest.LastMethodSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
CANCEL
ENDIF
IF (loRest.ResponseStatusCode <> 200) THEN
? "SES returned HTTP " + STR(loRest.ResponseStatusCode) + " " + lcResponseText
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
CANCEL
ENDIF
loResponse = CreateObject('Chilkat.JsonObject')
lnSuccess = loResponse.Load(lcResponseText)
IF (lnSuccess <> 1) THEN
? loResponse.LastErrorText
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
RELEASE loResponse
CANCEL
ENDIF
lnCount = loResponse.SizeOfArray("BulkEmailEntryResults")
IF (lnCount <> loRequest.SizeOfArray("BulkEmailEntries")) THEN
? "Incomplete results. Reconcile the original batch before retrying."
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
RELEASE loResponse
CANCEL
ENDIF
i = 0
DO WHILE (i < lnCount)
loResponse.I = i
loRequest.I = i
lcRecipient = loRequest.StringOf("BulkEmailEntries[i].Destination.ToAddresses[0]")
lcStatus = loResponse.StringOf("BulkEmailEntryResults[i].Status")
IF (lcStatus = "SUCCESS") THEN
? lcRecipient + " accepted: " + loResponse.StringOf("BulkEmailEntryResults[i].MessageId")
ELSE
IF ((lcStatus = "ACCOUNT_THROTTLED") OR (lcStatus = "TRANSIENT_FAILURE")) THEN
? lcRecipient + " retry later: " + lcStatus
ELSE
? lcRecipient + " review before retry: " + lcStatus + " " + loResponse.StringOf("BulkEmailEntryResults[i].Error")
ENDIF
ENDIF
i = i + 1
ENDDO
RELEASE loRequest
RELEASE loFirstReminder
RELEASE loSecondReminder
RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
RELEASE loResponse