AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$bSuccess = False
Local $sDomainName = "example.com"
Local $bCheckExisting = False
; Use the same AWS Region for the identity, endpoint, and Signature Version 4.
Local $sRegion = "us-west-2"
$oHost = ObjCreate("Chilkat.StringBuilder")
$oHost.Append("email.")
$oHost.Append($sRegion)
$oHost.Append(".amazonaws.com")
$oSigner = ObjCreate("Chilkat.AuthAws")
; Supply the credentials from your application's credential provider.
$oSigner.AccessKey = "AWS_ACCESS_KEY_ID"
$oSigner.SecretKey = "AWS_SECRET_ACCESS_KEY"
$oSigner.Region = $sRegion
$oSigner.ServiceName = "ses"
$oConnection = ObjCreate("Chilkat.Socket")
$oConnection.RequireSslCertVerify = True
$bSuccess = $oConnection.Connect($oHost.GetAsString(),443,True,10000)
If ($bSuccess <> True) Then
ConsoleWrite($oConnection.LastErrorText & @CRLF)
Exit
EndIf
$oRest = ObjCreate("Chilkat.Rest")
$bSuccess = $oRest.UseConnection($oConnection,False)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oRest.SetAuthAws($oSigner)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
; For temporary AWS credentials, supply the session token from the same provider.
Local $sessionToken = ""
If ($sessionToken <> "") Then
$oRest.AddQueryParam("X-Amz-Security-Token",$sessionToken)
EndIf
Local $sResponseText = ""
If ($bCheckExisting = True) Then
$oPath = ObjCreate("Chilkat.StringBuilder")
$oPath.Append("/v2/email/identities/")
$oPath.Append($sDomainName)
$sResponseText = $oRest.FullRequestNoBody("GET",$oPath.GetAsString())
Else
$oIdentity = ObjCreate("Chilkat.JsonObject")
$oIdentity.UpdateString("EmailIdentity",$sDomainName)
$oRest.AddHeader("Content-Type","application/json")
$sResponseText = $oRest.FullRequestString("POST","/v2/email/identities",$oIdentity.Emit())
EndIf
If ($oRest.LastMethodSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
If ($oRest.ResponseStatusCode <> 200) Then
ConsoleWrite("SES returned HTTP " & $oRest.ResponseStatusCode & " " & $sResponseText & @CRLF)
Exit
EndIf
$oResponse = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oResponse.Load($sResponseText)
If ($bSuccess <> True) Then
ConsoleWrite($oResponse.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("DKIM status: " & $oResponse.StringOf("DkimAttributes.Status") & @CRLF)
ConsoleWrite("Verified for sending: " & $oResponse.BoolOf("VerifiedForSendingStatus") & @CRLF)
Local $iCount = $oResponse.SizeOfArray("DkimAttributes.Tokens")
If ($iCount < 1) Then
ConsoleWrite("No Easy DKIM tokens were returned. Check this identity's DKIM configuration." & @CRLF)
Exit
EndIf
If ($oResponse.HasMember("DkimAttributes.SigningHostedZone") <> True) Then
ConsoleWrite("Find the CNAME targets for this identity in the SES console." & @CRLF)
Exit
EndIf
Local $sZone = $oResponse.StringOf("DkimAttributes.SigningHostedZone")
Local $i = 0
While ($i < $iCount)
$oResponse.I = $i
Local $sToken = $oResponse.StringOf("DkimAttributes.Tokens[i]")
ConsoleWrite($sToken & "._domainkey." & $sDomainName & " CNAME " & $sToken & "." & $sZone & @CRLF)
$i = $i + 1
Wend