Sample code for 30+ languages & platforms
VBScript

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 VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
success = 0

'  Look up the address exactly as stored, including any plus tag.
address = "avery+orders@example.com"
region = "us-west-2"
accessKey = "AWS_ACCESS_KEY_ID"
secretKey = "AWS_SECRET_ACCESS_KEY"
sessionToken = ""
set host = CreateObject("Chilkat.StringBuilder")
success = host.Append("email.")
success = host.Append(region)
success = host.Append(".amazonaws.com")
set mailbox = CreateObject("Chilkat.StringBuilder")
success = mailbox.Append(address)
set path = CreateObject("Chilkat.StringBuilder")
success = path.Append("/v2/email/suppression/addresses/")
success = path.Append(mailbox.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.
set canonicalPath = CreateObject("Chilkat.StringBuilder")
success = canonicalPath.Append(path.GetAsString())
replaced = canonicalPath.Replace("%","%25")
set clock = CreateObject("Chilkat.CkDateTime")
success = clock.SetFromCurrentSystemTime()
set stamp = CreateObject("Chilkat.StringBuilder")
success = stamp.Append(clock.GetAsTimestamp(0))
replaced = stamp.Replace("-","")
replaced = stamp.Replace(":","")
date = stamp.GetRange(0,8,0)
set rest = CreateObject("Chilkat.Rest")
success = rest.AddHeader("Host",host.GetAsString())
success = rest.AddHeader("x-amz-date",stamp.GetAsString())
set headers = CreateObject("Chilkat.StringBuilder")
success = headers.Append("host:")
success = headers.Append(host.GetAsString())
success = headers.Append(vbLf & "x-amz-date:")
success = headers.Append(stamp.GetAsString())
success = headers.Append(vbLf)
signedHeaders = "host;x-amz-date"
If (sessionToken <> "") Then
    success = rest.AddHeader("x-amz-security-token",sessionToken)
    success = headers.Append("x-amz-security-token:")
    success = headers.Append(sessionToken)
    success = headers.Append(vbLf)
    signedHeaders = "host;x-amz-date;x-amz-security-token"
End If

set crypto = CreateObject("Chilkat.Crypt2")
crypto.HashAlgorithm = "sha256"
crypto.MacAlgorithm = "hmac"
crypto.EncodingMode = "hexlower"
crypto.Charset = "utf-8"
set canonical = CreateObject("Chilkat.StringBuilder")
success = canonical.Append("GET" & vbLf)
success = canonical.Append(canonicalPath.GetAsString())
success = canonical.Append(vbLf & vbLf)
success = canonical.Append(headers.GetAsString())
success = canonical.Append(vbLf)
success = canonical.Append(signedHeaders)
success = canonical.Append(vbLf)
success = canonical.Append(crypto.HashStringENC(""))
set scope = CreateObject("Chilkat.StringBuilder")
success = scope.Append(date)
success = scope.Append("/")
success = scope.Append(region)
success = scope.Append("/ses/aws4_request")
set toSign = CreateObject("Chilkat.StringBuilder")
success = toSign.Append("AWS4-HMAC-SHA256" & vbLf)
success = toSign.Append(stamp.GetAsString())
success = toSign.Append(vbLf)
success = toSign.Append(scope.GetAsString())
success = toSign.Append(vbLf)
success = toSign.Append(crypto.HashStringENC(canonical.GetAsString()))

'  Derive the signing key one HMAC at a time. Decode each intermediate key from hex.
set seed = CreateObject("Chilkat.StringBuilder")
success = seed.Append("AWS4")
success = seed.Append(secretKey)
success = crypto.SetMacKeyString(seed.GetAsString())
key = crypto.MacStringENC(date)
success = crypto.SetMacKeyEncoded(key,"hex")
key = crypto.MacStringENC(region)
success = crypto.SetMacKeyEncoded(key,"hex")
key = crypto.MacStringENC("ses")
success = crypto.SetMacKeyEncoded(key,"hex")
key = crypto.MacStringENC("aws4_request")
success = crypto.SetMacKeyEncoded(key,"hex")
signature = crypto.MacStringENC(toSign.GetAsString())
set authorization = CreateObject("Chilkat.StringBuilder")
success = authorization.Append("AWS4-HMAC-SHA256 Credential=")
success = authorization.Append(accessKey)
success = authorization.Append("/")
success = authorization.Append(scope.GetAsString())
success = authorization.Append(", SignedHeaders=")
success = authorization.Append(signedHeaders)
success = authorization.Append(", Signature=")
success = authorization.Append(signature)
success = rest.AddHeader("Authorization",authorization.GetAsString())
set connection = CreateObject("Chilkat.Socket")
connection.RequireSslCertVerify = 1
success = connection.Connect(host.GetAsString(),443,1,10000)
If (success <> 1) Then
    outFile.WriteLine(connection.LastErrorText)
    WScript.Quit
End If

success = rest.UseConnection(connection,0)
If (success <> 1) Then
    outFile.WriteLine(rest.LastErrorText)
    WScript.Quit
End If

responseText = rest.FullRequestNoBody("GET",path.GetAsString())
If (rest.LastMethodSuccess <> 1) Then
    outFile.WriteLine(rest.LastErrorText)
    WScript.Quit
End If

If (rest.ResponseStatusCode = 404) Then
    outFile.WriteLine("No account suppression entry for this address in this Region.")
    WScript.Quit
End If

If (rest.ResponseStatusCode <> 200) Then
    outFile.WriteLine("SES returned HTTP " & rest.ResponseStatusCode & " " & responseText)
    WScript.Quit
End If

set response = CreateObject("Chilkat.JsonObject")
success = response.Load(responseText)
If (success <> 1) Then
    outFile.WriteLine(response.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine(response.StringOf("SuppressedDestination.EmailAddress"))
outFile.WriteLine("Reason: " & response.StringOf("SuppressedDestination.Reason"))
outFile.WriteLine("Last updated (Unix seconds): " & response.StringOf("SuppressedDestination.LastUpdateTime"))

outFile.Close