Sample code for 30+ languages & platforms
DataFlex

Amazon SES v2: Verify a sending domain with Easy DKIM

See more Amazon SES Examples

Use a domain you control. Run once to create the regional identity, publish the returned CNAMEs with your DNS provider, then set checkExisting to true and run again to read the status. The target suffix comes from SES. If your DNS provider appends the domain automatically, enter just the relative record name.

CreateEmailIdentity · GetEmailIdentity · Easy DKIM records

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String sDomainName
    Boolean iCheckExisting
    String sRegion
    Handle hoHost
    Variant vSigner
    Handle hoSigner
    Variant vConnection
    Handle hoConnection
    Handle hoRest
    String sSessionToken
    String sResponseText
    Handle hoPath
    Handle hoIdentity
    Handle hoResponse
    Integer iCount
    String sZone
    Integer i
    String sToken
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    Move False To iSuccess

    Move "example.com" To sDomainName
    Move False To iCheckExisting
    //  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

    Move "" To sResponseText
    If (iCheckExisting = True) Begin
        Get Create (RefClass(cComChilkatStringBuilder)) To hoPath
        If (Not(IsComObjectCreated(hoPath))) Begin
            Send CreateComObject of hoPath
        End
        Get ComAppend Of hoPath "/v2/email/identities/" To iSuccess
        Get ComAppend Of hoPath sDomainName To iSuccess
        Get ComGetAsString Of hoPath To sTemp1
        Get ComFullRequestNoBody Of hoRest "GET" sTemp1 To sResponseText
    End
    Else Begin
        Get Create (RefClass(cComChilkatJsonObject)) To hoIdentity
        If (Not(IsComObjectCreated(hoIdentity))) Begin
            Send CreateComObject of hoIdentity
        End
        Get ComUpdateString Of hoIdentity "EmailIdentity" sDomainName To iSuccess
        Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess
        Get ComEmit Of hoIdentity To sTemp1
        Get ComFullRequestString Of hoRest "POST" "/v2/email/identities" sTemp1 To sResponseText
    End

    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 ComStringOf Of hoResponse "DkimAttributes.Status" To sTemp1
    Showln "DKIM status: " sTemp1
    Get ComBoolOf Of hoResponse "VerifiedForSendingStatus" To bTemp1
    Showln "Verified for sending: " bTemp1
    Get ComSizeOfArray Of hoResponse "DkimAttributes.Tokens" To iCount
    If (iCount < 1) Begin
        Showln "No Easy DKIM tokens were returned. Check this identity's DKIM configuration."
        Procedure_Return
    End

    Get ComHasMember Of hoResponse "DkimAttributes.SigningHostedZone" To bTemp1
    If (bTemp1 <> True) Begin
        Showln "Find the CNAME targets for this identity in the SES console."
        Procedure_Return
    End

    Get ComStringOf Of hoResponse "DkimAttributes.SigningHostedZone" To sZone
    Move 0 To i
    While (i < iCount)
        Set ComI Of hoResponse To i
        Get ComStringOf Of hoResponse "DkimAttributes.Tokens[i]" To sToken
        Showln sToken "._domainkey." sDomainName " CNAME " sToken "." sZone
        Move (i + 1) To i
    Loop



End_Procedure