Xojo Plugin
Xojo Plugin
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 Xojo Plugin Downloads
Dim success As Boolean
success = False
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
Dim request As New Chilkat.JsonObject
success = request.UpdateString("FromEmailAddress","sender@example.com")
success = request.UpdateString("DefaultContent.Template.TemplateContent.Subject","Appointment reminder")
success = request.UpdateString("DefaultContent.Template.TemplateContent.Text","Hello {{name}}, your appointment is {{slot}}.")
success = request.UpdateString("DefaultContent.Template.TemplateData","{""name"":""there"",""slot"":""in your booking confirmation""}")
Dim firstReminder As New Chilkat.JsonObject
success = firstReminder.UpdateString("name","Avery")
success = firstReminder.UpdateString("slot","Tuesday at 9 AM Central")
success = request.UpdateString("BulkEmailEntries[0].Destination.ToAddresses[0]","avery@example.com")
success = request.UpdateString("BulkEmailEntries[0].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData",firstReminder.Emit())
Dim secondReminder As New Chilkat.JsonObject
success = secondReminder.UpdateString("name","Robin")
success = secondReminder.UpdateString("slot","Wednesday at 2 PM Central")
success = request.UpdateString("BulkEmailEntries[1].Destination.ToAddresses[0]","robin@example.com")
success = request.UpdateString("BulkEmailEntries[1].ReplacementEmailContent.ReplacementTemplate.ReplacementTemplateData",secondReminder.Emit())
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
Dim region As String
region = "us-west-2"
Dim host As New Chilkat.StringBuilder
success = host.Append("email.")
success = host.Append(region)
success = host.Append(".amazonaws.com")
Dim signer As 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"
Dim connection As New Chilkat.Socket
connection.RequireSslCertVerify = True
success = connection.Connect(host.GetAsString(),443,True,10000)
If (success <> True) Then
System.DebugLog(connection.LastErrorText)
Return
End If
Dim rest As New Chilkat.Rest
success = rest.UseConnection(connection,False)
If (success <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
success = rest.SetAuthAws(signer)
If (success <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
// For temporary AWS credentials, supply the session token from the same provider.
Dim sessionToken As String
sessionToken = ""
If (sessionToken <> "") Then
success = rest.AddQueryParam("X-Amz-Security-Token",sessionToken)
End If
success = rest.AddHeader("Content-Type","application/json")
Dim responseText As String
responseText = rest.FullRequestString("POST","/v2/email/outbound-bulk-emails",request.Emit())
If (rest.LastMethodSuccess <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
If (rest.ResponseStatusCode <> 200) Then
System.DebugLog("SES returned HTTP " + Str(rest.ResponseStatusCode) + " " + responseText)
Return
End If
Dim response As New Chilkat.JsonObject
success = response.Load(responseText)
If (success <> True) Then
System.DebugLog(response.LastErrorText)
Return
End If
Dim count As Int32
count = response.SizeOfArray("BulkEmailEntryResults")
If (count <> request.SizeOfArray("BulkEmailEntries")) Then
System.DebugLog("Incomplete results. Reconcile the original batch before retrying.")
Return
End If
Dim i As Int32
i = 0
While (i < count)
response.I = i
request.I = i
Dim recipient As String
recipient = request.StringOf("BulkEmailEntries[i].Destination.ToAddresses[0]")
Dim status As String
status = response.StringOf("BulkEmailEntryResults[i].Status")
If (status = "SUCCESS") Then
System.DebugLog(recipient + " accepted: " + response.StringOf("BulkEmailEntryResults[i].MessageId"))
Else
If ((status = "ACCOUNT_THROTTLED") Or (status = "TRANSIENT_FAILURE")) Then
System.DebugLog(recipient + " retry later: " + status)
Else
System.DebugLog(recipient + " review before retry: " + status + " " + response.StringOf("BulkEmailEntryResults[i].Error"))
End If
End If
i = i + 1
Wend