Sample code for 30+ languages & platforms
AutoIt

Amazon SES v2: Check an address on the account suppression list

See more Amazon SES Examples

Look up one address in the sending Region with ses:GetSuppressedDestination. The record distinguishes a bounce from a complaint. An absent record tells you only that this account suppression lookup found no entry. The example signs the exact encoded mailbox path and also works with temporary credentials.

GetSuppressedDestination

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.
$bSuccess = False

;  Look up the address exactly as stored, including any plus tag.
Local $sAddress = "avery+orders@example.com"
Local $sRegion = "us-west-2"
Local $sAccessKey = "AWS_ACCESS_KEY_ID"
Local $secretKey = "AWS_SECRET_ACCESS_KEY"
Local $sessionToken = ""
$oHost = ObjCreate("Chilkat.StringBuilder")
$oHost.Append("email.")
$oHost.Append($sRegion)
$oHost.Append(".amazonaws.com")
$oMailbox = ObjCreate("Chilkat.StringBuilder")
$oMailbox.Append($sAddress)
$oPath = ObjCreate("Chilkat.StringBuilder")
$oPath.Append("/v2/email/suppression/addresses/")
$oPath.Append($oMailbox.GetEncoded("url_rfc3986","utf-8"))

;  SigV4 for SES encodes the wire path a second time in the canonical request.
;  Only the canonical copy escapes the percent signs. Send the original path over HTTPS.
$oCanonicalPath = ObjCreate("Chilkat.StringBuilder")
$oCanonicalPath.Append($oPath.GetAsString())
Local $iReplaced = $oCanonicalPath.Replace("%","%25")
$oClock = ObjCreate("Chilkat.CkDateTime")
$oClock.SetFromCurrentSystemTime()
$oStamp = ObjCreate("Chilkat.StringBuilder")
$oStamp.Append($oClock.GetAsTimestamp(False))
$iReplaced = $oStamp.Replace("-","")
$iReplaced = $oStamp.Replace(":","")
Local $sDate = $oStamp.GetRange(0,8,False)
$oRest = ObjCreate("Chilkat.Rest")
$oRest.AddHeader("Host",$oHost.GetAsString())
$oRest.AddHeader("x-amz-date",$oStamp.GetAsString())
$oHeaders = ObjCreate("Chilkat.StringBuilder")
$oHeaders.Append("host:")
$oHeaders.Append($oHost.GetAsString())
$oHeaders.Append(@LF & "x-amz-date:")
$oHeaders.Append($oStamp.GetAsString())
$oHeaders.Append(@LF)
Local $signedHeaders = "host;x-amz-date"
If ($sessionToken <> "") Then
    $oRest.AddHeader("x-amz-security-token",$sessionToken)
    $oHeaders.Append("x-amz-security-token:")
    $oHeaders.Append($sessionToken)
    $oHeaders.Append(@LF)
    $signedHeaders = "host;x-amz-date;x-amz-security-token"
EndIf

$oCrypto = ObjCreate("Chilkat.Crypt2")
$oCrypto.HashAlgorithm = "sha256"
$oCrypto.MacAlgorithm = "hmac"
$oCrypto.EncodingMode = "hexlower"
$oCrypto.Charset = "utf-8"
$oCanonical = ObjCreate("Chilkat.StringBuilder")
$oCanonical.Append("GET" & @LF)
$oCanonical.Append($oCanonicalPath.GetAsString())
$oCanonical.Append(@LF & @LF)
$oCanonical.Append($oHeaders.GetAsString())
$oCanonical.Append(@LF)
$oCanonical.Append($signedHeaders)
$oCanonical.Append(@LF)
$oCanonical.Append($oCrypto.HashStringENC(""))
$oScope = ObjCreate("Chilkat.StringBuilder")
$oScope.Append($sDate)
$oScope.Append("/")
$oScope.Append($sRegion)
$oScope.Append("/ses/aws4_request")
$oToSign = ObjCreate("Chilkat.StringBuilder")
$oToSign.Append("AWS4-HMAC-SHA256" & @LF)
$oToSign.Append($oStamp.GetAsString())
$oToSign.Append(@LF)
$oToSign.Append($oScope.GetAsString())
$oToSign.Append(@LF)
$oToSign.Append($oCrypto.HashStringENC($oCanonical.GetAsString()))

;  Derive the signing key one HMAC at a time. Decode each intermediate key from hex.
$oSeed = ObjCreate("Chilkat.StringBuilder")
$oSeed.Append("AWS4")
$oSeed.Append($secretKey)
$oCrypto.SetMacKeyString($oSeed.GetAsString())
Local $sKey = $oCrypto.MacStringENC($sDate)
$oCrypto.SetMacKeyEncoded($sKey,"hex")
$sKey = $oCrypto.MacStringENC($sRegion)
$oCrypto.SetMacKeyEncoded($sKey,"hex")
$sKey = $oCrypto.MacStringENC("ses")
$oCrypto.SetMacKeyEncoded($sKey,"hex")
$sKey = $oCrypto.MacStringENC("aws4_request")
$oCrypto.SetMacKeyEncoded($sKey,"hex")
Local $signature = $oCrypto.MacStringENC($oToSign.GetAsString())
$oAuthorization = ObjCreate("Chilkat.StringBuilder")
$oAuthorization.Append("AWS4-HMAC-SHA256 Credential=")
$oAuthorization.Append($sAccessKey)
$oAuthorization.Append("/")
$oAuthorization.Append($oScope.GetAsString())
$oAuthorization.Append(", SignedHeaders=")
$oAuthorization.Append($signedHeaders)
$oAuthorization.Append(", Signature=")
$oAuthorization.Append($signature)
$oRest.AddHeader("Authorization",$oAuthorization.GetAsString())
$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

$bSuccess = $oRest.UseConnection($oConnection,False)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

Local $sResponseText = $oRest.FullRequestNoBody("GET",$oPath.GetAsString())
If ($oRest.LastMethodSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

If ($oRest.ResponseStatusCode = 404) Then
    ConsoleWrite("No account suppression entry for this address in this Region." & @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($oResponse.StringOf("SuppressedDestination.EmailAddress") & @CRLF)
ConsoleWrite("Reason: " & $oResponse.StringOf("SuppressedDestination.Reason") & @CRLF)
ConsoleWrite("Last updated (Unix seconds): " & $oResponse.StringOf("SuppressedDestination.LastUpdateTime") & @CRLF)