Visual Basic 6.0
Visual Basic 6.0
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 Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
success = 0
' 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 ChilkatStringBuilder
success = host.Append("email.")
success = host.Append(region)
success = host.Append(".amazonaws.com")
Dim mailbox As New ChilkatStringBuilder
success = mailbox.Append(address)
Dim path As New ChilkatStringBuilder
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 ChilkatStringBuilder
success = canonicalPath.Append(path.GetAsString())
Dim replaced As Long
replaced = canonicalPath.Replace("%","%25")
Dim clock As New CkDateTime
success = clock.SetFromCurrentSystemTime()
Dim stamp As New ChilkatStringBuilder
success = stamp.Append(clock.GetAsTimestamp(0))
replaced = stamp.Replace("-","")
replaced = stamp.Replace(":","")
Dim date As String
date = stamp.GetRange(0,8,0)
Dim rest As New ChilkatRest
success = rest.AddHeader("Host",host.GetAsString())
success = rest.AddHeader("x-amz-date",stamp.GetAsString())
Dim headers As New ChilkatStringBuilder
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)
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(vbLf)
signedHeaders = "host;x-amz-date;x-amz-security-token"
End If
Dim crypto As New ChilkatCrypt2
crypto.HashAlgorithm = "sha256"
crypto.MacAlgorithm = "hmac"
crypto.EncodingMode = "hexlower"
crypto.Charset = "utf-8"
Dim canonical As New ChilkatStringBuilder
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(""))
Dim scope As New ChilkatStringBuilder
success = scope.Append(date)
success = scope.Append("/")
success = scope.Append(region)
success = scope.Append("/ses/aws4_request")
Dim toSign As New ChilkatStringBuilder
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.
Dim seed As New ChilkatStringBuilder
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 ChilkatStringBuilder
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 ChilkatSocket
connection.RequireSslCertVerify = 1
success = connection.Connect(host.GetAsString(),443,1,10000)
If (success <> 1) Then
Debug.Print connection.LastErrorText
Exit Sub
End If
success = rest.UseConnection(connection,0)
If (success <> 1) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
Dim responseText As String
responseText = rest.FullRequestNoBody("GET",path.GetAsString())
If (rest.LastMethodSuccess <> 1) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
If (rest.ResponseStatusCode = 404) Then
Debug.Print "No account suppression entry for this address in this Region."
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.Print "SES returned HTTP " & rest.ResponseStatusCode & " " & responseText
Exit Sub
End If
Dim response As New ChilkatJsonObject
success = response.Load(responseText)
If (success <> 1) Then
Debug.Print response.LastErrorText
Exit Sub
End If
Debug.Print response.StringOf("SuppressedDestination.EmailAddress")
Debug.Print "Reason: " & response.StringOf("SuppressedDestination.Reason")
Debug.Print "Last updated (Unix seconds): " & response.StringOf("SuppressedDestination.LastUpdateTime")