Xojo Plugin
Xojo Plugin
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.
Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
// Look up the address exactly as stored, including any plus tag.
Dim address As String
address = "avery+orders@example.com"
Dim region As String
region = "us-west-2"
Dim accessKey As String
accessKey = "AWS_ACCESS_KEY_ID"
Dim secretKey As String
secretKey = "AWS_SECRET_ACCESS_KEY"
Dim sessionToken As String
sessionToken = ""
Dim host As New Chilkat.StringBuilder
success = host.Append("email.")
success = host.Append(region)
success = host.Append(".amazonaws.com")
Dim mailbox As New Chilkat.StringBuilder
success = mailbox.Append(address)
Dim path As New 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.
Dim canonicalPath As New Chilkat.StringBuilder
success = canonicalPath.Append(path.GetAsString())
Dim replaced As Int32
replaced = canonicalPath.Replace("%","%25")
Dim clock As New Chilkat.CkDateTime
success = clock.SetFromCurrentSystemTime()
Dim stamp As New Chilkat.StringBuilder
success = stamp.Append(clock.GetAsTimestamp(False))
replaced = stamp.Replace("-","")
replaced = stamp.Replace(":","")
Dim date As String
date = stamp.GetRange(0,8,False)
Dim rest As New Chilkat.Rest
success = rest.AddHeader("Host",host.GetAsString())
success = rest.AddHeader("x-amz-date",stamp.GetAsString())
Dim headers As New Chilkat.StringBuilder
success = headers.Append("host:")
success = headers.Append(host.GetAsString())
success = headers.Append(EndOfLine.Unix + "x-amz-date:")
success = headers.Append(stamp.GetAsString())
success = headers.Append(EndOfLine.Unix)
Dim signedHeaders As String
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(EndOfLine.Unix)
signedHeaders = "host;x-amz-date;x-amz-security-token"
End If
Dim crypto As New Chilkat.Crypt2
crypto.HashAlgorithm = "sha256"
crypto.MacAlgorithm = "hmac"
crypto.EncodingMode = "hexlower"
crypto.Charset = "utf-8"
Dim canonical As New Chilkat.StringBuilder
success = canonical.Append("GET" + EndOfLine.Unix)
success = canonical.Append(canonicalPath.GetAsString())
success = canonical.Append(EndOfLine.Unix + EndOfLine.Unix)
success = canonical.Append(headers.GetAsString())
success = canonical.Append(EndOfLine.Unix)
success = canonical.Append(signedHeaders)
success = canonical.Append(EndOfLine.Unix)
success = canonical.Append(crypto.HashStringENC(""))
Dim scope As New Chilkat.StringBuilder
success = scope.Append(date)
success = scope.Append("/")
success = scope.Append(region)
success = scope.Append("/ses/aws4_request")
Dim toSign As New Chilkat.StringBuilder
success = toSign.Append("AWS4-HMAC-SHA256" + EndOfLine.Unix)
success = toSign.Append(stamp.GetAsString())
success = toSign.Append(EndOfLine.Unix)
success = toSign.Append(scope.GetAsString())
success = toSign.Append(EndOfLine.Unix)
success = toSign.Append(crypto.HashStringENC(canonical.GetAsString()))
// Derive the signing key one HMAC at a time. Decode each intermediate key from hex.
Dim seed As New Chilkat.StringBuilder
success = seed.Append("AWS4")
success = seed.Append(secretKey)
success = crypto.SetMacKeyString(seed.GetAsString())
Dim key As String
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")
Dim signature As String
signature = crypto.MacStringENC(toSign.GetAsString())
Dim authorization As New 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())
Dim connection As New Chilkat.Socket
connection.RequireSslCertVerify = True
success = connection.Connect(host.GetAsString(),443,True,10000)
If (success <> True) Then
System.DebugLog(connection.LastErrorText)
Return
End If
success = rest.UseConnection(connection,False)
If (success <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
Dim responseText As String
responseText = rest.FullRequestNoBody("GET",path.GetAsString())
If (rest.LastMethodSuccess <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
If (rest.ResponseStatusCode = 404) Then
System.DebugLog("No account suppression entry for this address in this Region.")
Return
End If
If (rest.ResponseStatusCode <> 200) Then
System.DebugLog("SES returned HTTP " + Str(rest.ResponseStatusCode) + " " + responseText)
Return
End If
Dim response As New Chilkat.JsonObject
success = response.Load(responseText)
If (success <> True) Then
System.DebugLog(response.LastErrorText)
Return
End If
System.DebugLog(response.StringOf("SuppressedDestination.EmailAddress"))
System.DebugLog("Reason: " + response.StringOf("SuppressedDestination.Reason"))
System.DebugLog("Last updated (Unix seconds): " + response.StringOf("SuppressedDestination.LastUpdateTime"))