Sample code for 30+ languages & platforms
Tcl

Amazon SES v2: Check regional sending access and quota

See more Amazon SES Examples

Run this in the Region where your application sends mail. Check whether SES accepts sends, whether the account has production access, and how much of its rolling 24-hour quota is in use. Sandbox accounts can send to verified recipients and the mailbox simulator. Sender verification is regional.

GetAccount · Sandbox restrictions

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
set success 0

#  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
set region "us-west-2"
set host [new_CkStringBuilder]

CkStringBuilder_Append $host "email."
CkStringBuilder_Append $host $region
CkStringBuilder_Append $host ".amazonaws.com"

set signer [new_CkAuthAws]

#  Supply the credentials from your application's credential provider.
CkAuthAws_put_AccessKey $signer "AWS_ACCESS_KEY_ID"
CkAuthAws_put_SecretKey $signer "AWS_SECRET_ACCESS_KEY"
CkAuthAws_put_Region $signer $region
CkAuthAws_put_ServiceName $signer "ses"

set connection [new_CkSocket]

CkSocket_put_RequireSslCertVerify $connection 1
set success [CkSocket_Connect $connection [CkStringBuilder_getAsString $host] 443 1 10000]
if {$success != 1} then {
    puts [CkSocket_lastErrorText $connection]
    delete_CkStringBuilder $host
    delete_CkAuthAws $signer
    delete_CkSocket $connection
    exit
}

set rest [new_CkRest]

set success [CkRest_UseConnection $rest $connection 0]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkStringBuilder $host
    delete_CkAuthAws $signer
    delete_CkSocket $connection
    delete_CkRest $rest
    exit
}

set success [CkRest_SetAuthAws $rest $signer]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkStringBuilder $host
    delete_CkAuthAws $signer
    delete_CkSocket $connection
    delete_CkRest $rest
    exit
}

#  For temporary AWS credentials, supply the session token from the same provider.
set sessionToken ""
if {$sessionToken != ""} then {
    CkRest_AddQueryParam $rest "X-Amz-Security-Token" $sessionToken
}

set responseText [CkRest_fullRequestNoBody $rest "GET" "/v2/email/account"]
if {[CkRest_get_LastMethodSuccess $rest] != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkStringBuilder $host
    delete_CkAuthAws $signer
    delete_CkSocket $connection
    delete_CkRest $rest
    exit
}

if {[CkRest_get_ResponseStatusCode $rest] != 200} then {
    puts "SES returned HTTP [CkRest_get_ResponseStatusCode $rest] $responseText"
    delete_CkStringBuilder $host
    delete_CkAuthAws $signer
    delete_CkSocket $connection
    delete_CkRest $rest
    exit
}

set response [new_CkJsonObject]

set success [CkJsonObject_Load $response $responseText]
if {$success != 1} then {
    puts [CkJsonObject_lastErrorText $response]
    delete_CkStringBuilder $host
    delete_CkAuthAws $signer
    delete_CkSocket $connection
    delete_CkRest $rest
    delete_CkJsonObject $response
    exit
}

puts "Sending enabled: [CkJsonObject_BoolOf $response SendingEnabled]"
puts "Production access: [CkJsonObject_BoolOf $response ProductionAccessEnabled]"
puts "Recipients sent to in the last 24 hours: [CkJsonObject_stringOf $response SendQuota.SentLast24Hours]"
puts "24-hour recipient quota (-1 means unlimited): [CkJsonObject_stringOf $response SendQuota.Max24HourSend]"
puts "Maximum recipients per second: [CkJsonObject_stringOf $response SendQuota.MaxSendRate]"

delete_CkStringBuilder $host
delete_CkAuthAws $signer
delete_CkSocket $connection
delete_CkRest $rest
delete_CkJsonObject $response