AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$bSuccess = False
$oRequest = ObjCreate("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 = ObjCreate("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 = ObjCreate("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.
Local $sRegion = "us-west-2"
$oHost = ObjCreate("Chilkat.StringBuilder")
$oHost.Append("email.")
$oHost.Append($sRegion)
$oHost.Append(".amazonaws.com")
$oSigner = ObjCreate("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 = $sRegion
$oSigner.ServiceName = "ses"
$oConnection = ObjCreate("Chilkat.Socket")
$oConnection.RequireSslCertVerify = True
$bSuccess = $oConnection.Connect($oHost.GetAsString(),443,True,10000)
If ($bSuccess <> True) Then
ConsoleWrite($oConnection.LastErrorText & @CRLF)
Exit
EndIf
$oRest = ObjCreate("Chilkat.Rest")
$bSuccess = $oRest.UseConnection($oConnection,False)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oRest.SetAuthAws($oSigner)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
; For temporary AWS credentials, supply the session token from the same provider.
Local $sessionToken = ""
If ($sessionToken <> "") Then
$oRest.AddQueryParam("X-Amz-Security-Token",$sessionToken)
EndIf
$oRest.AddHeader("Content-Type","application/json")
Local $sResponseText = $oRest.FullRequestString("POST","/v2/email/outbound-bulk-emails",$oRequest.Emit())
If ($oRest.LastMethodSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
If ($oRest.ResponseStatusCode <> 200) Then
ConsoleWrite("SES returned HTTP " & $oRest.ResponseStatusCode & " " & $sResponseText & @CRLF)
Exit
EndIf
$oResponse = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oResponse.Load($sResponseText)
If ($bSuccess <> True) Then
ConsoleWrite($oResponse.LastErrorText & @CRLF)
Exit
EndIf
Local $iCount = $oResponse.SizeOfArray("BulkEmailEntryResults")
If ($iCount <> $oRequest.SizeOfArray("BulkEmailEntries")) Then
ConsoleWrite("Incomplete results. Reconcile the original batch before retrying." & @CRLF)
Exit
EndIf
Local $i = 0
While ($i < $iCount)
$oResponse.I = $i
$oRequest.I = $i
Local $sRecipient = $oRequest.StringOf("BulkEmailEntries[i].Destination.ToAddresses[0]")
Local $status = $oResponse.StringOf("BulkEmailEntryResults[i].Status")
If ($status = "SUCCESS") Then
ConsoleWrite($sRecipient & " accepted: " & $oResponse.StringOf("BulkEmailEntryResults[i].MessageId") & @CRLF)
Else
If (($status = "ACCOUNT_THROTTLED") Or ($status = "TRANSIENT_FAILURE")) Then
ConsoleWrite($sRecipient & " retry later: " & $status & @CRLF)
Else
ConsoleWrite($sRecipient & " review before retry: " & $status & " " & $oResponse.StringOf("BulkEmailEntryResults[i].Error") & @CRLF)
EndIf
EndIf
$i = $i + 1
Wend