Xojo Plugin
Xojo Plugin
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 Xojo Plugin Downloads
Dim success As Boolean
success = False
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
Dim domainName As String
domainName = "example.com"
Dim checkExisting As Boolean
checkExisting = False
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
Dim region As String
region = "us-west-2"
Dim host As New Chilkat.StringBuilder
success = host.Append("email.")
success = host.Append(region)
success = host.Append(".amazonaws.com")
Dim signer As New Chilkat.AuthAws
// Supply the credentials from your application's credential provider.
signer.AccessKey = "AWS_ACCESS_KEY_ID"
signer.SecretKey = "AWS_SECRET_ACCESS_KEY"
signer.Region = region
signer.ServiceName = "ses"
Dim connection As New Chilkat.Socket
connection.RequireSslCertVerify = True
success = connection.Connect(host.GetAsString(),443,True,10000)
If (success <> True) Then
System.DebugLog(connection.LastErrorText)
Return
End If
Dim rest As New Chilkat.Rest
success = rest.UseConnection(connection,False)
If (success <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
success = rest.SetAuthAws(signer)
If (success <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
// For temporary AWS credentials, supply the session token from the same provider.
Dim sessionToken As String
sessionToken = ""
If (sessionToken <> "") Then
success = rest.AddQueryParam("X-Amz-Security-Token",sessionToken)
End If
Dim responseText As String
responseText = ""
If (checkExisting = True) Then
Dim path As New Chilkat.StringBuilder
success = path.Append("/v2/email/identities/")
success = path.Append(domainName)
responseText = rest.FullRequestNoBody("GET",path.GetAsString())
Else
Dim identity As New Chilkat.JsonObject
success = identity.UpdateString("EmailIdentity",domainName)
success = rest.AddHeader("Content-Type","application/json")
responseText = rest.FullRequestString("POST","/v2/email/identities",identity.Emit())
End If
If (rest.LastMethodSuccess <> True) Then
System.DebugLog(rest.LastErrorText)
Return
End If
If (rest.ResponseStatusCode <> 200) Then
System.DebugLog("SES returned HTTP " + Str(rest.ResponseStatusCode) + " " + responseText)
Return
End If
Dim response As New Chilkat.JsonObject
success = response.Load(responseText)
If (success <> True) Then
System.DebugLog(response.LastErrorText)
Return
End If
System.DebugLog("DKIM status: " + response.StringOf("DkimAttributes.Status"))
System.DebugLog("Verified for sending: " + Str(response.BoolOf("VerifiedForSendingStatus")))
Dim count As Int32
count = response.SizeOfArray("DkimAttributes.Tokens")
If (count < 1) Then
System.DebugLog("No Easy DKIM tokens were returned. Check this identity's DKIM configuration.")
Return
End If
If (response.HasMember("DkimAttributes.SigningHostedZone") <> True) Then
System.DebugLog("Find the CNAME targets for this identity in the SES console.")
Return
End If
Dim zone As String
zone = response.StringOf("DkimAttributes.SigningHostedZone")
Dim i As Int32
i = 0
While (i < count)
response.I = i
Dim token As String
token = response.StringOf("DkimAttributes.Tokens[i]")
System.DebugLog(token + "._domainkey." + domainName + " CNAME " + token + "." + zone)
i = i + 1
Wend