VB.NET
VB.NET
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 VB.NET Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
Dim request As 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""}")
Dim firstReminder As 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())
Dim secondReminder As 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.
Dim region As String = "us-west-2"
Dim host As New Chilkat.StringBuilder
host.Append("email.")
host.Append(region)
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
Debug.WriteLine(connection.LastErrorText)
Exit Sub
End If
Dim rest As New Chilkat.Rest
success = rest.UseConnection(connection,False)
If (success <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
success = rest.SetAuthAws(signer)
If (success <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
' For temporary AWS credentials, supply the session token from the same provider.
Dim sessionToken As String = ""
If (sessionToken <> "") Then
rest.AddQueryParam("X-Amz-Security-Token",sessionToken)
End If
rest.AddHeader("Content-Type","application/json")
Dim responseText As String = rest.FullRequestString("POST","/v2/email/outbound-bulk-emails",request.Emit())
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine("SES returned HTTP " & rest.ResponseStatusCode & " " & responseText)
Exit Sub
End If
Dim response As New Chilkat.JsonObject
success = response.Load(responseText)
If (success <> True) Then
Debug.WriteLine(response.LastErrorText)
Exit Sub
End If
Dim count As Integer = response.SizeOfArray("BulkEmailEntryResults")
If (count <> request.SizeOfArray("BulkEmailEntries")) Then
Debug.WriteLine("Incomplete results. Reconcile the original batch before retrying.")
Exit Sub
End If
Dim i As Integer = 0
While (i < count)
response.I = i
request.I = i
Dim recipient As String = request.StringOf("BulkEmailEntries[i].Destination.ToAddresses[0]")
Dim status As String = response.StringOf("BulkEmailEntryResults[i].Status")
If (status = "SUCCESS") Then
Debug.WriteLine(recipient & " accepted: " & response.StringOf("BulkEmailEntryResults[i].MessageId"))
Else
If ((status = "ACCOUNT_THROTTLED") Or (status = "TRANSIENT_FAILURE")) Then
Debug.WriteLine(recipient & " retry later: " & status)
Else
Debug.WriteLine(recipient & " review before retry: " & status & " " & response.StringOf("BulkEmailEntryResults[i].Error"))
End If
End If
i = i + 1
End While