PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
string ls_Address
string ls_Region
string ls_AccessKey
string ls_SecretKey
string ls_SessionToken
oleobject loo_Host
oleobject loo_Mailbox
oleobject loo_Path
oleobject loo_CanonicalPath
long li_Replaced
oleobject loo_Clock
oleobject loo_Stamp
string ls_Date
oleobject loo_Rest
oleobject loo_Headers
string ls_SignedHeaders
oleobject loo_Crypto
oleobject loo_Canonical
oleobject loo_Scope
oleobject loo_ToSign
oleobject loo_Seed
string ls_Key
string ls_Signature
oleobject loo_Authorization
oleobject loo_Connection
string ls_ResponseText
oleobject loo_Response
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
// Look up the address exactly as stored, including any plus tag.
ls_Address = "avery+orders@example.com"
ls_Region = "us-west-2"
ls_AccessKey = "AWS_ACCESS_KEY_ID"
ls_SecretKey = "AWS_SECRET_ACCESS_KEY"
ls_SessionToken = ""
loo_Host = create oleobject
li_rc = loo_Host.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
destroy loo_Host
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Host.Append("email.")
loo_Host.Append(ls_Region)
loo_Host.Append(".amazonaws.com")
loo_Mailbox = create oleobject
li_rc = loo_Mailbox.ConnectToNewObject("Chilkat.StringBuilder")
loo_Mailbox.Append(ls_Address)
loo_Path = create oleobject
li_rc = loo_Path.ConnectToNewObject("Chilkat.StringBuilder")
loo_Path.Append("/v2/email/suppression/addresses/")
loo_Path.Append(loo_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.
loo_CanonicalPath = create oleobject
li_rc = loo_CanonicalPath.ConnectToNewObject("Chilkat.StringBuilder")
loo_CanonicalPath.Append(loo_Path.GetAsString())
li_Replaced = loo_CanonicalPath.Replace("%","%25")
loo_Clock = create oleobject
li_rc = loo_Clock.ConnectToNewObject("Chilkat.CkDateTime")
loo_Clock.SetFromCurrentSystemTime()
loo_Stamp = create oleobject
li_rc = loo_Stamp.ConnectToNewObject("Chilkat.StringBuilder")
loo_Stamp.Append(loo_Clock.GetAsTimestamp(0))
li_Replaced = loo_Stamp.Replace("-","")
li_Replaced = loo_Stamp.Replace(":","")
ls_Date = loo_Stamp.GetRange(0,8,0)
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
loo_Rest.AddHeader("Host",loo_Host.GetAsString())
loo_Rest.AddHeader("x-amz-date",loo_Stamp.GetAsString())
loo_Headers = create oleobject
li_rc = loo_Headers.ConnectToNewObject("Chilkat.StringBuilder")
loo_Headers.Append("host:")
loo_Headers.Append(loo_Host.GetAsString())
loo_Headers.Append("~nx-amz-date:")
loo_Headers.Append(loo_Stamp.GetAsString())
loo_Headers.Append("~n")
ls_SignedHeaders = "host;x-amz-date"
if ls_SessionToken <> "" then
loo_Rest.AddHeader("x-amz-security-token",ls_SessionToken)
loo_Headers.Append("x-amz-security-token:")
loo_Headers.Append(ls_SessionToken)
loo_Headers.Append("~n")
ls_SignedHeaders = "host;x-amz-date;x-amz-security-token"
end if
loo_Crypto = create oleobject
li_rc = loo_Crypto.ConnectToNewObject("Chilkat.Crypt2")
loo_Crypto.HashAlgorithm = "sha256"
loo_Crypto.MacAlgorithm = "hmac"
loo_Crypto.EncodingMode = "hexlower"
loo_Crypto.Charset = "utf-8"
loo_Canonical = create oleobject
li_rc = loo_Canonical.ConnectToNewObject("Chilkat.StringBuilder")
loo_Canonical.Append("GET~n")
loo_Canonical.Append(loo_CanonicalPath.GetAsString())
loo_Canonical.Append("~n~n")
loo_Canonical.Append(loo_Headers.GetAsString())
loo_Canonical.Append("~n")
loo_Canonical.Append(ls_SignedHeaders)
loo_Canonical.Append("~n")
loo_Canonical.Append(loo_Crypto.HashStringENC(""))
loo_Scope = create oleobject
li_rc = loo_Scope.ConnectToNewObject("Chilkat.StringBuilder")
loo_Scope.Append(ls_Date)
loo_Scope.Append("/")
loo_Scope.Append(ls_Region)
loo_Scope.Append("/ses/aws4_request")
loo_ToSign = create oleobject
li_rc = loo_ToSign.ConnectToNewObject("Chilkat.StringBuilder")
loo_ToSign.Append("AWS4-HMAC-SHA256~n")
loo_ToSign.Append(loo_Stamp.GetAsString())
loo_ToSign.Append("~n")
loo_ToSign.Append(loo_Scope.GetAsString())
loo_ToSign.Append("~n")
loo_ToSign.Append(loo_Crypto.HashStringENC(loo_Canonical.GetAsString()))
// Derive the signing key one HMAC at a time. Decode each intermediate key from hex.
loo_Seed = create oleobject
li_rc = loo_Seed.ConnectToNewObject("Chilkat.StringBuilder")
loo_Seed.Append("AWS4")
loo_Seed.Append(ls_SecretKey)
loo_Crypto.SetMacKeyString(loo_Seed.GetAsString())
ls_Key = loo_Crypto.MacStringENC(ls_Date)
loo_Crypto.SetMacKeyEncoded(ls_Key,"hex")
ls_Key = loo_Crypto.MacStringENC(ls_Region)
loo_Crypto.SetMacKeyEncoded(ls_Key,"hex")
ls_Key = loo_Crypto.MacStringENC("ses")
loo_Crypto.SetMacKeyEncoded(ls_Key,"hex")
ls_Key = loo_Crypto.MacStringENC("aws4_request")
loo_Crypto.SetMacKeyEncoded(ls_Key,"hex")
ls_Signature = loo_Crypto.MacStringENC(loo_ToSign.GetAsString())
loo_Authorization = create oleobject
li_rc = loo_Authorization.ConnectToNewObject("Chilkat.StringBuilder")
loo_Authorization.Append("AWS4-HMAC-SHA256 Credential=")
loo_Authorization.Append(ls_AccessKey)
loo_Authorization.Append("/")
loo_Authorization.Append(loo_Scope.GetAsString())
loo_Authorization.Append(", SignedHeaders=")
loo_Authorization.Append(ls_SignedHeaders)
loo_Authorization.Append(", Signature=")
loo_Authorization.Append(ls_Signature)
loo_Rest.AddHeader("Authorization",loo_Authorization.GetAsString())
loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")
loo_Connection.RequireSslCertVerify = 1
li_Success = loo_Connection.Connect(loo_Host.GetAsString(),443,1,10000)
if li_Success <> 1 then
Write-Debug loo_Connection.LastErrorText
destroy loo_Host
destroy loo_Mailbox
destroy loo_Path
destroy loo_CanonicalPath
destroy loo_Clock
destroy loo_Stamp
destroy loo_Rest
destroy loo_Headers
destroy loo_Crypto
destroy loo_Canonical
destroy loo_Scope
destroy loo_ToSign
destroy loo_Seed
destroy loo_Authorization
destroy loo_Connection
return
end if
li_Success = loo_Rest.UseConnection(loo_Connection,0)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Host
destroy loo_Mailbox
destroy loo_Path
destroy loo_CanonicalPath
destroy loo_Clock
destroy loo_Stamp
destroy loo_Rest
destroy loo_Headers
destroy loo_Crypto
destroy loo_Canonical
destroy loo_Scope
destroy loo_ToSign
destroy loo_Seed
destroy loo_Authorization
destroy loo_Connection
return
end if
ls_ResponseText = loo_Rest.FullRequestNoBody("GET",loo_Path.GetAsString())
if loo_Rest.LastMethodSuccess <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Host
destroy loo_Mailbox
destroy loo_Path
destroy loo_CanonicalPath
destroy loo_Clock
destroy loo_Stamp
destroy loo_Rest
destroy loo_Headers
destroy loo_Crypto
destroy loo_Canonical
destroy loo_Scope
destroy loo_ToSign
destroy loo_Seed
destroy loo_Authorization
destroy loo_Connection
return
end if
if loo_Rest.ResponseStatusCode = 404 then
Write-Debug "No account suppression entry for this address in this Region."
destroy loo_Host
destroy loo_Mailbox
destroy loo_Path
destroy loo_CanonicalPath
destroy loo_Clock
destroy loo_Stamp
destroy loo_Rest
destroy loo_Headers
destroy loo_Crypto
destroy loo_Canonical
destroy loo_Scope
destroy loo_ToSign
destroy loo_Seed
destroy loo_Authorization
destroy loo_Connection
return
end if
if loo_Rest.ResponseStatusCode <> 200 then
Write-Debug "SES returned HTTP " + string(loo_Rest.ResponseStatusCode) + " " + ls_ResponseText
destroy loo_Host
destroy loo_Mailbox
destroy loo_Path
destroy loo_CanonicalPath
destroy loo_Clock
destroy loo_Stamp
destroy loo_Rest
destroy loo_Headers
destroy loo_Crypto
destroy loo_Canonical
destroy loo_Scope
destroy loo_ToSign
destroy loo_Seed
destroy loo_Authorization
destroy loo_Connection
return
end if
loo_Response = create oleobject
li_rc = loo_Response.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Response.Load(ls_ResponseText)
if li_Success <> 1 then
Write-Debug loo_Response.LastErrorText
destroy loo_Host
destroy loo_Mailbox
destroy loo_Path
destroy loo_CanonicalPath
destroy loo_Clock
destroy loo_Stamp
destroy loo_Rest
destroy loo_Headers
destroy loo_Crypto
destroy loo_Canonical
destroy loo_Scope
destroy loo_ToSign
destroy loo_Seed
destroy loo_Authorization
destroy loo_Connection
destroy loo_Response
return
end if
Write-Debug loo_Response.StringOf("SuppressedDestination.EmailAddress")
Write-Debug "Reason: " + loo_Response.StringOf("SuppressedDestination.Reason")
Write-Debug "Last updated (Unix seconds): " + loo_Response.StringOf("SuppressedDestination.LastUpdateTime")
destroy loo_Host
destroy loo_Mailbox
destroy loo_Path
destroy loo_CanonicalPath
destroy loo_Clock
destroy loo_Stamp
destroy loo_Rest
destroy loo_Headers
destroy loo_Crypto
destroy loo_Canonical
destroy loo_Scope
destroy loo_ToSign
destroy loo_Seed
destroy loo_Authorization
destroy loo_Connection
destroy loo_Response