AutoIt
AutoIt
Amazon SES v2: Publish delivery events to SNS and correlate a tagged send
See more Amazon SES Examples
Use an existing configuration set and Standard SNS topic in the same Region. Grant SES permission to publish to the topic and subscribe your consumer. Configure the destination once, then set configureDestination to false to send a test. In the SES event inside the SNS Message, eventType identifies the outcome, mail.messageId matches the send result, and mail.tags.notification_ref[0] identifies the application record. Use the SES bounce or complaint simulator address to exercise those outcomes.
Configure the SNS destination · SES event payload
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$bSuccess = False
Local $bConfigureDestination = True
Local $setName = "application-mail"
; 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
If ($bConfigureDestination = True) Then
$oPath = ObjCreate("Chilkat.StringBuilder")
$oPath.Append("/v2/email/configuration-sets/")
$oPath.Append($setName)
$oPath.Append("/event-destinations")
$oDestination = ObjCreate("Chilkat.JsonObject")
$oDestination.UpdateString("EventDestinationName","delivery-to-sns")
$oDestination.UpdateString("EventDestination.MatchingEventTypes[0]","DELIVERY")
$oDestination.UpdateString("EventDestination.MatchingEventTypes[1]","BOUNCE")
$oDestination.UpdateString("EventDestination.MatchingEventTypes[2]","COMPLAINT")
$oDestination.UpdateString("EventDestination.SnsDestination.TopicArn","arn:aws:sns:us-west-2:123456789012:ses-delivery")
$oDestination.UpdateBool("EventDestination.Enabled",True)
$oRest.AddHeader("Content-Type","application/json")
Local $setupResponse = $oRest.FullRequestString("POST",$oPath.GetAsString(),$oDestination.Emit())
If ($oRest.LastMethodSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
If ($oRest.ResponseStatusCode <> 200) Then
ConsoleWrite("SES returned HTTP " & $oRest.ResponseStatusCode & " " & $setupResponse & @CRLF)
Exit
EndIf
ConsoleWrite("Destination created. Use the send branch to test it." & @CRLF)
Exit
EndIf
$oRequest = ObjCreate("Chilkat.JsonObject")
$oRequest.UpdateString("FromEmailAddress","sender@example.com")
$oRequest.UpdateString("Destination.ToAddresses[0]","success@simulator.amazonses.com")
$oRequest.UpdateString("Content.Simple.Subject.Data","Delivery event test")
$oRequest.UpdateString("Content.Simple.Body.Text.Data","Exercise the application-mail configuration set.")
$oRequest.UpdateString("EmailTags[0].Name","notification_ref")
$oRequest.UpdateString("EmailTags[0].Value","notify-1042")
$oRequest.UpdateString("ConfigurationSetName",$setName)
$oRest.AddHeader("Content-Type","application/json")
Local $sResponseText = $oRest.FullRequestString("POST","/v2/email/outbound-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
ConsoleWrite("SES accepted the message: " & $oResponse.StringOf("MessageId") & @CRLF)