DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
String sAddress
String sRegion
String sAccessKey
String sSecretKey
String sSessionToken
Handle hoHost
Handle hoMailbox
Handle hoPath
Handle hoCanonicalPath
Integer iReplaced
Handle hoClock
Handle hoStamp
String sDate
Handle hoRest
Handle hoHeaders
String sSignedHeaders
Handle hoCrypto
Handle hoCanonical
Handle hoScope
Handle hoToSign
Handle hoSeed
String sKey
String sSignature
Handle hoAuthorization
Variant vConnection
Handle hoConnection
String sResponseText
Handle hoResponse
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Move False To iSuccess
// Look up the address exactly as stored, including any plus tag.
Move "avery+orders@example.com" To sAddress
Move "us-west-2" To sRegion
Move "AWS_ACCESS_KEY_ID" To sAccessKey
Move "AWS_SECRET_ACCESS_KEY" To sSecretKey
Move "" To sSessionToken
Get Create (RefClass(cComChilkatStringBuilder)) To hoHost
If (Not(IsComObjectCreated(hoHost))) Begin
Send CreateComObject of hoHost
End
Get ComAppend Of hoHost "email." To iSuccess
Get ComAppend Of hoHost sRegion To iSuccess
Get ComAppend Of hoHost ".amazonaws.com" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoMailbox
If (Not(IsComObjectCreated(hoMailbox))) Begin
Send CreateComObject of hoMailbox
End
Get ComAppend Of hoMailbox sAddress To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoPath
If (Not(IsComObjectCreated(hoPath))) Begin
Send CreateComObject of hoPath
End
Get ComAppend Of hoPath "/v2/email/suppression/addresses/" To iSuccess
Get ComGetEncoded Of hoMailbox "url_rfc3986" "utf-8" To sTemp1
Get ComAppend Of hoPath sTemp1 To iSuccess
// 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.
Get Create (RefClass(cComChilkatStringBuilder)) To hoCanonicalPath
If (Not(IsComObjectCreated(hoCanonicalPath))) Begin
Send CreateComObject of hoCanonicalPath
End
Get ComGetAsString Of hoPath To sTemp1
Get ComAppend Of hoCanonicalPath sTemp1 To iSuccess
Get ComReplace Of hoCanonicalPath "%" "%25" To iReplaced
Get Create (RefClass(cComCkDateTime)) To hoClock
If (Not(IsComObjectCreated(hoClock))) Begin
Send CreateComObject of hoClock
End
Get ComSetFromCurrentSystemTime Of hoClock To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoStamp
If (Not(IsComObjectCreated(hoStamp))) Begin
Send CreateComObject of hoStamp
End
Get ComGetAsTimestamp Of hoClock False To sTemp1
Get ComAppend Of hoStamp sTemp1 To iSuccess
Get ComReplace Of hoStamp "-" "" To iReplaced
Get ComReplace Of hoStamp ":" "" To iReplaced
Get ComGetRange Of hoStamp 0 8 False To sDate
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Get ComGetAsString Of hoHost To sTemp1
Get ComAddHeader Of hoRest "Host" sTemp1 To iSuccess
Get ComGetAsString Of hoStamp To sTemp1
Get ComAddHeader Of hoRest "x-amz-date" sTemp1 To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoHeaders
If (Not(IsComObjectCreated(hoHeaders))) Begin
Send CreateComObject of hoHeaders
End
Get ComAppend Of hoHeaders "host:" To iSuccess
Get ComGetAsString Of hoHost To sTemp1
Get ComAppend Of hoHeaders sTemp1 To iSuccess
Get ComAppend Of hoHeaders (character(10)) + "x-amz-date:" To iSuccess
Get ComGetAsString Of hoStamp To sTemp1
Get ComAppend Of hoHeaders sTemp1 To iSuccess
Get ComAppend Of hoHeaders (character(10)) To iSuccess
Move "host;x-amz-date" To sSignedHeaders
If (sSessionToken <> "") Begin
Get ComAddHeader Of hoRest "x-amz-security-token" sSessionToken To iSuccess
Get ComAppend Of hoHeaders "x-amz-security-token:" To iSuccess
Get ComAppend Of hoHeaders sSessionToken To iSuccess
Get ComAppend Of hoHeaders (character(10)) To iSuccess
Move "host;x-amz-date;x-amz-security-token" To sSignedHeaders
End
Get Create (RefClass(cComChilkatCrypt2)) To hoCrypto
If (Not(IsComObjectCreated(hoCrypto))) Begin
Send CreateComObject of hoCrypto
End
Set ComHashAlgorithm Of hoCrypto To "sha256"
Set ComMacAlgorithm Of hoCrypto To "hmac"
Set ComEncodingMode Of hoCrypto To "hexlower"
Set ComCharset Of hoCrypto To "utf-8"
Get Create (RefClass(cComChilkatStringBuilder)) To hoCanonical
If (Not(IsComObjectCreated(hoCanonical))) Begin
Send CreateComObject of hoCanonical
End
Get ComAppend Of hoCanonical "GET" + (character(10)) To iSuccess
Get ComGetAsString Of hoCanonicalPath To sTemp1
Get ComAppend Of hoCanonical sTemp1 To iSuccess
Get ComAppend Of hoCanonical (character(10)) + (character(10)) To iSuccess
Get ComGetAsString Of hoHeaders To sTemp1
Get ComAppend Of hoCanonical sTemp1 To iSuccess
Get ComAppend Of hoCanonical (character(10)) To iSuccess
Get ComAppend Of hoCanonical sSignedHeaders To iSuccess
Get ComAppend Of hoCanonical (character(10)) To iSuccess
Get ComHashStringENC Of hoCrypto "" To sTemp1
Get ComAppend Of hoCanonical sTemp1 To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoScope
If (Not(IsComObjectCreated(hoScope))) Begin
Send CreateComObject of hoScope
End
Get ComAppend Of hoScope sDate To iSuccess
Get ComAppend Of hoScope "/" To iSuccess
Get ComAppend Of hoScope sRegion To iSuccess
Get ComAppend Of hoScope "/ses/aws4_request" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoToSign
If (Not(IsComObjectCreated(hoToSign))) Begin
Send CreateComObject of hoToSign
End
Get ComAppend Of hoToSign "AWS4-HMAC-SHA256" + (character(10)) To iSuccess
Get ComGetAsString Of hoStamp To sTemp1
Get ComAppend Of hoToSign sTemp1 To iSuccess
Get ComAppend Of hoToSign (character(10)) To iSuccess
Get ComGetAsString Of hoScope To sTemp1
Get ComAppend Of hoToSign sTemp1 To iSuccess
Get ComAppend Of hoToSign (character(10)) To iSuccess
Get ComHashStringENC Of hoCrypto (ComGetAsString(hoCanonical)) To sTemp1
Get ComAppend Of hoToSign sTemp1 To iSuccess
// Derive the signing key one HMAC at a time. Decode each intermediate key from hex.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSeed
If (Not(IsComObjectCreated(hoSeed))) Begin
Send CreateComObject of hoSeed
End
Get ComAppend Of hoSeed "AWS4" To iSuccess
Get ComAppend Of hoSeed sSecretKey To iSuccess
Get ComGetAsString Of hoSeed To sTemp1
Get ComSetMacKeyString Of hoCrypto sTemp1 To iSuccess
Get ComMacStringENC Of hoCrypto sDate To sKey
Get ComSetMacKeyEncoded Of hoCrypto sKey "hex" To iSuccess
Get ComMacStringENC Of hoCrypto sRegion To sKey
Get ComSetMacKeyEncoded Of hoCrypto sKey "hex" To iSuccess
Get ComMacStringENC Of hoCrypto "ses" To sKey
Get ComSetMacKeyEncoded Of hoCrypto sKey "hex" To iSuccess
Get ComMacStringENC Of hoCrypto "aws4_request" To sKey
Get ComSetMacKeyEncoded Of hoCrypto sKey "hex" To iSuccess
Get ComGetAsString Of hoToSign To sTemp1
Get ComMacStringENC Of hoCrypto sTemp1 To sSignature
Get Create (RefClass(cComChilkatStringBuilder)) To hoAuthorization
If (Not(IsComObjectCreated(hoAuthorization))) Begin
Send CreateComObject of hoAuthorization
End
Get ComAppend Of hoAuthorization "AWS4-HMAC-SHA256 Credential=" To iSuccess
Get ComAppend Of hoAuthorization sAccessKey To iSuccess
Get ComAppend Of hoAuthorization "/" To iSuccess
Get ComGetAsString Of hoScope To sTemp1
Get ComAppend Of hoAuthorization sTemp1 To iSuccess
Get ComAppend Of hoAuthorization ", SignedHeaders=" To iSuccess
Get ComAppend Of hoAuthorization sSignedHeaders To iSuccess
Get ComAppend Of hoAuthorization ", Signature=" To iSuccess
Get ComAppend Of hoAuthorization sSignature To iSuccess
Get ComGetAsString Of hoAuthorization To sTemp1
Get ComAddHeader Of hoRest "Authorization" sTemp1 To iSuccess
Get Create (RefClass(cComChilkatSocket)) To hoConnection
If (Not(IsComObjectCreated(hoConnection))) Begin
Send CreateComObject of hoConnection
End
Set ComRequireSslCertVerify Of hoConnection To True
Get ComGetAsString Of hoHost To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 10000 To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoConnection To sTemp1
Showln sTemp1
Procedure_Return
End
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComGetAsString Of hoPath To sTemp1
Get ComFullRequestNoBody Of hoRest "GET" sTemp1 To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 = 404) Begin
Showln "No account suppression entry for this address in this Region."
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "SES returned HTTP " iTemp1 " " sResponseText
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoResponse
If (Not(IsComObjectCreated(hoResponse))) Begin
Send CreateComObject of hoResponse
End
Get ComLoad Of hoResponse sResponseText To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoResponse To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStringOf Of hoResponse "SuppressedDestination.EmailAddress" To sTemp1
Showln sTemp1
Get ComStringOf Of hoResponse "SuppressedDestination.Reason" To sTemp1
Showln "Reason: " sTemp1
Get ComStringOf Of hoResponse "SuppressedDestination.LastUpdateTime" To sTemp1
Showln "Last updated (Unix seconds): " sTemp1
End_Procedure