Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String sRegion
    Handle hoHost
    Variant vSigner
    Handle hoSigner
    Variant vConnection
    Handle hoConnection
    Handle hoRest
    String sSessionToken
    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

    //  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
    Move "us-west-2" To sRegion
    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(cComChilkatAuthAws)) To hoSigner
    If (Not(IsComObjectCreated(hoSigner))) Begin
        Send CreateComObject of hoSigner
    End
    //  Supply the credentials from your application's credential provider.
    Set ComAccessKey Of hoSigner To "AWS_ACCESS_KEY_ID"
    Set ComSecretKey Of hoSigner To "AWS_SECRET_ACCESS_KEY"
    Set ComRegion Of hoSigner To sRegion
    Set ComServiceName Of hoSigner To "ses"

    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 Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    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 pvComObject of hoSigner to vSigner
    Get ComSetAuthAws Of hoRest vSigner To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  For temporary AWS credentials, supply the session token from the same provider.
    Move "" To sSessionToken
    If (sSessionToken <> "") Begin
        Get ComAddQueryParam Of hoRest "X-Amz-Security-Token" sSessionToken To iSuccess
    End

    Get ComFullRequestNoBody Of hoRest "GET" "/v2/email/account" 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 <> 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 ComBoolOf Of hoResponse "SendingEnabled" To bTemp1
    Showln "Sending enabled: " bTemp1
    Get ComBoolOf Of hoResponse "ProductionAccessEnabled" To bTemp1
    Showln "Production access: " bTemp1
    Get ComStringOf Of hoResponse "SendQuota.SentLast24Hours" To sTemp1
    Showln "Recipients sent to in the last 24 hours: " sTemp1
    Get ComStringOf Of hoResponse "SendQuota.Max24HourSend" To sTemp1
    Showln "24-hour recipient quota (-1 means unlimited): " sTemp1
    Get ComStringOf Of hoResponse "SendQuota.MaxSendRate" To sTemp1
    Showln "Maximum recipients per second: " sTemp1


End_Procedure