AutoIt Requires Chilkat v11.0.0+
AutoIt
Sign an email and send the signed bytes over SMTP
See more DKIM Examples
Compose the email, render it to MIME once, add its DKIM signature, and submit those same bytes to an SMTP server. Put blind-copy recipients in the SMTP envelope only so their addresses stay out of the visible headers.
Use an authorized SMTP account and your own sender domain. Publish the selector’s matching public key first. If your relay rewrites signed content, have it apply the signature after its final edits. A successful SMTP submission means the relay accepted the message. A recipient can then verify it with the public key in DNS.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oMail = ObjCreate("Chilkat.MailMan")
$oMail.SmtpHost = "smtp.example.com"
$oMail.SmtpPort = 465
$oMail.SmtpSsl = True
$oMail.RequireSslCertVerify = True
$oMail.SmtpUsername = "SMTP_USERNAME"
$oMail.SmtpPassword = "SMTP_PASSWORD"
$oEmail = ObjCreate("Chilkat.Email")
$oEmail.From = "Workshop team <updates@example.com>"
$oEmail.Subject = "Workshop registration"
$oEmail.Body = "Registration opens on Monday."
$bSuccess = $oEmail.AddTo("Newsletter editor","editor@example.net")
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
; Render after all headers, recipients, and content are final.
$oMessage = ObjCreate("Chilkat.BinData")
$bSuccess = $oMail.RenderToMimeBd($oEmail,$oMessage)
If ($bSuccess <> True) Then
ConsoleWrite($oMail.LastErrorText & @CRLF)
Exit
EndIf
; Supply your RSA signing key. For an encrypted PEM, get its password from your credential store.
$oPrivateKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oPrivateKey.LoadAnyFormatFile("dkim-private.pem","")
If ($bSuccess <> True) Then
ConsoleWrite($oPrivateKey.LastErrorText & @CRLF)
Exit
EndIf
$oSigner = ObjCreate("Chilkat.Dkim")
$oSigner.DkimDomain = "example.com"
$oSigner.DkimSelector = "mail2026"
$oSigner.DkimAlg = "rsa-sha256"
$bSuccess = $oSigner.SetDkimPrivateKey($oPrivateKey)
If ($bSuccess <> True) Then
ConsoleWrite($oSigner.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oSigner.DkimSign($oMessage)
If ($bSuccess <> True) Then
ConsoleWrite($oSigner.LastErrorText & @CRLF)
Exit
EndIf
; archive@example.com is an envelope-only blind copy.
Local $sRecipients = "editor@example.net,archive@example.com"
$bSuccess = $oMail.SendMimeBd("updates@example.com",$sRecipients,$oMessage)
If ($bSuccess <> True) Then
ConsoleWrite($oMail.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("SMTP relay accepted the signed message." & @CRLF)
$bSuccess = $oMail.CloseSmtpConnection()
If ($bSuccess <> True) Then
ConsoleWrite("The SMTP session did not close cleanly." & @CRLF)
EndIf