Sample code for 30+ languages & platforms
VB.NET

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 VB.NET Downloads

VB.NET
Dim success As Boolean = 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 = "avery+orders@example.com"
Dim region As String = "us-west-2"
Dim accessKey As String = "AWS_ACCESS_KEY_ID"
Dim secretKey As String = "AWS_SECRET_ACCESS_KEY"
Dim sessionToken As String = ""
Dim host As New Chilkat.StringBuilder
host.Append("email.")
host.Append(region)
host.Append(".amazonaws.com")
Dim mailbox As New Chilkat.StringBuilder
mailbox.Append(address)
Dim path As New Chilkat.StringBuilder
path.Append("/v2/email/suppression/addresses/")
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
canonicalPath.Append(path.GetAsString())
Dim replaced As Integer = canonicalPath.Replace("%","%25")
Dim clock As New Chilkat.CkDateTime
clock.SetFromCurrentSystemTime()
Dim stamp As New Chilkat.StringBuilder
stamp.Append(clock.GetAsTimestamp(False))
replaced = stamp.Replace("-","")
replaced = stamp.Replace(":","")
Dim date As String = stamp.GetRange(0,8,False)
Dim rest As New Chilkat.Rest
rest.AddHeader("Host",host.GetAsString())
rest.AddHeader("x-amz-date",stamp.GetAsString())
Dim headers As New Chilkat.StringBuilder
headers.Append("host:")
headers.Append(host.GetAsString())
headers.Append(vbLf & "x-amz-date:")
headers.Append(stamp.GetAsString())
headers.Append(vbLf)
Dim signedHeaders As String = "host;x-amz-date"
If (sessionToken <> "") Then
    rest.AddHeader("x-amz-security-token",sessionToken)
    headers.Append("x-amz-security-token:")
    headers.Append(sessionToken)
    headers.Append(vbLf)
    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
canonical.Append("GET" & vbLf)
canonical.Append(canonicalPath.GetAsString())
canonical.Append(vbLf & vbLf)
canonical.Append(headers.GetAsString())
canonical.Append(vbLf)
canonical.Append(signedHeaders)
canonical.Append(vbLf)
canonical.Append(crypto.HashStringENC(""))
Dim scope As New Chilkat.StringBuilder
scope.Append(date)
scope.Append("/")
scope.Append(region)
scope.Append("/ses/aws4_request")
Dim toSign As New Chilkat.StringBuilder
toSign.Append("AWS4-HMAC-SHA256" & vbLf)
toSign.Append(stamp.GetAsString())
toSign.Append(vbLf)
toSign.Append(scope.GetAsString())
toSign.Append(vbLf)
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
seed.Append("AWS4")
seed.Append(secretKey)
crypto.SetMacKeyString(seed.GetAsString())
Dim key As String = crypto.MacStringENC(date)
crypto.SetMacKeyEncoded(key,"hex")
key = crypto.MacStringENC(region)
crypto.SetMacKeyEncoded(key,"hex")
key = crypto.MacStringENC("ses")
crypto.SetMacKeyEncoded(key,"hex")
key = crypto.MacStringENC("aws4_request")
crypto.SetMacKeyEncoded(key,"hex")
Dim signature As String = crypto.MacStringENC(toSign.GetAsString())
Dim authorization As New Chilkat.StringBuilder
authorization.Append("AWS4-HMAC-SHA256 Credential=")
authorization.Append(accessKey)
authorization.Append("/")
authorization.Append(scope.GetAsString())
authorization.Append(", SignedHeaders=")
authorization.Append(signedHeaders)
authorization.Append(", Signature=")
authorization.Append(signature)
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
    Debug.WriteLine(connection.LastErrorText)
    Exit Sub
End If

success = rest.UseConnection(connection,False)
If (success <> True) Then
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If


Dim responseText As String = rest.FullRequestNoBody("GET",path.GetAsString())
If (rest.LastMethodSuccess <> True) Then
    Debug.WriteLine(rest.LastErrorText)
    Exit Sub
End If

If (rest.ResponseStatusCode = 404) Then
    Debug.WriteLine("No account suppression entry for this address in this Region.")
    Exit Sub
End If

If (rest.ResponseStatusCode <> 200) Then
    Debug.WriteLine("SES returned HTTP " & rest.ResponseStatusCode & " " & responseText)
    Exit Sub
End If

Dim response As New Chilkat.JsonObject
success = response.Load(responseText)
If (success <> True) Then
    Debug.WriteLine(response.LastErrorText)
    Exit Sub
End If

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