Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL lcDomainName
LOCAL lnCheckExisting
LOCAL lcRegion
LOCAL loHost
LOCAL loSigner
LOCAL loConnection
LOCAL loRest
LOCAL lcSessionToken
LOCAL lcResponseText
LOCAL loPath
LOCAL loIdentity
LOCAL loResponse
LOCAL lnCount
LOCAL lcZone
LOCAL i
LOCAL lcToken

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0

lcDomainName = "example.com"
lnCheckExisting = 0
*  Use the same AWS Region for the identity, endpoint, and Signature Version 4.
lcRegion = "us-west-2"
loHost = CreateObject('Chilkat.StringBuilder')
loHost.Append("email.")
loHost.Append(lcRegion)
loHost.Append(".amazonaws.com")

loSigner = CreateObject('Chilkat.AuthAws')
*  Supply the credentials from your application's credential provider.
loSigner.AccessKey = "AWS_ACCESS_KEY_ID"
loSigner.SecretKey = "AWS_SECRET_ACCESS_KEY"
loSigner.Region = lcRegion
loSigner.ServiceName = "ses"

loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
lnSuccess = loConnection.Connect(loHost.GetAsString(),443,1,10000)
IF (lnSuccess <> 1) THEN
    ? loConnection.LastErrorText
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    CANCEL
ENDIF

loRest = CreateObject('Chilkat.Rest')
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    RELEASE loRest
    CANCEL
ENDIF

lnSuccess = loRest.SetAuthAws(loSigner)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    RELEASE loRest
    CANCEL
ENDIF

*  For temporary AWS credentials, supply the session token from the same provider.
lcSessionToken = ""
IF (lcSessionToken <> "") THEN
    loRest.AddQueryParam("X-Amz-Security-Token",lcSessionToken)
ENDIF

lcResponseText = ""
IF (lnCheckExisting = 1) THEN
    loPath = CreateObject('Chilkat.StringBuilder')
    loPath.Append("/v2/email/identities/")
    loPath.Append(lcDomainName)
    lcResponseText = loRest.FullRequestNoBody("GET",loPath.GetAsString())
ELSE
    loIdentity = CreateObject('Chilkat.JsonObject')
    loIdentity.UpdateString("EmailIdentity",lcDomainName)
    loRest.AddHeader("Content-Type","application/json")
    lcResponseText = loRest.FullRequestString("POST","/v2/email/identities",loIdentity.Emit())
ENDIF

IF (loRest.LastMethodSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    RELEASE loRest
    RELEASE loPath
    RELEASE loIdentity
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "SES returned HTTP " + STR(loRest.ResponseStatusCode) + " " + lcResponseText
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    RELEASE loRest
    RELEASE loPath
    RELEASE loIdentity
    CANCEL
ENDIF

loResponse = CreateObject('Chilkat.JsonObject')
lnSuccess = loResponse.Load(lcResponseText)
IF (lnSuccess <> 1) THEN
    ? loResponse.LastErrorText
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    RELEASE loRest
    RELEASE loPath
    RELEASE loIdentity
    RELEASE loResponse
    CANCEL
ENDIF

? "DKIM status: " + loResponse.StringOf("DkimAttributes.Status")
? "Verified for sending: " + STR(loResponse.BoolOf("VerifiedForSendingStatus"))
lnCount = loResponse.SizeOfArray("DkimAttributes.Tokens")
IF (lnCount < 1) THEN
    ? "No Easy DKIM tokens were returned. Check this identity's DKIM configuration."
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    RELEASE loRest
    RELEASE loPath
    RELEASE loIdentity
    RELEASE loResponse
    CANCEL
ENDIF

IF (loResponse.HasMember("DkimAttributes.SigningHostedZone") <> 1) THEN
    ? "Find the CNAME targets for this identity in the SES console."
    RELEASE loHost
    RELEASE loSigner
    RELEASE loConnection
    RELEASE loRest
    RELEASE loPath
    RELEASE loIdentity
    RELEASE loResponse
    CANCEL
ENDIF

lcZone = loResponse.StringOf("DkimAttributes.SigningHostedZone")
i = 0
DO WHILE (i < lnCount)
    loResponse.I = i
    lcToken = loResponse.StringOf("DkimAttributes.Tokens[i]")
    ? lcToken + "._domainkey." + lcDomainName + " CNAME " + lcToken + "." + lcZone
    i = i + 1
ENDDO

RELEASE loHost
RELEASE loSigner
RELEASE loConnection
RELEASE loRest
RELEASE loPath
RELEASE loIdentity
RELEASE loResponse