VBScript Requires Chilkat v11.0.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set mail = CreateObject("Chilkat.MailMan")
mail.SmtpHost = "smtp.example.com"
mail.SmtpPort = 465
mail.SmtpSsl = 1
mail.RequireSslCertVerify = 1
mail.SmtpUsername = "SMTP_USERNAME"
mail.SmtpPassword = "SMTP_PASSWORD"
set email = CreateObject("Chilkat.Email")
email.From = "Workshop team <updates@example.com>"
email.Subject = "Workshop registration"
email.Body = "Registration opens on Monday."
success = email.AddTo("Newsletter editor","editor@example.net")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
' Render after all headers, recipients, and content are final.
set message = CreateObject("Chilkat.BinData")
success = mail.RenderToMimeBd(email,message)
If (success <> 1) Then
outFile.WriteLine(mail.LastErrorText)
WScript.Quit
End If
' Supply your RSA signing key. For an encrypted PEM, get its password from your credential store.
set privateKey = CreateObject("Chilkat.PrivateKey")
success = privateKey.LoadAnyFormatFile("dkim-private.pem","")
If (success <> 1) Then
outFile.WriteLine(privateKey.LastErrorText)
WScript.Quit
End If
set signer = CreateObject("Chilkat.Dkim")
signer.DkimDomain = "example.com"
signer.DkimSelector = "mail2026"
signer.DkimAlg = "rsa-sha256"
success = signer.SetDkimPrivateKey(privateKey)
If (success <> 1) Then
outFile.WriteLine(signer.LastErrorText)
WScript.Quit
End If
success = signer.DkimSign(message)
If (success <> 1) Then
outFile.WriteLine(signer.LastErrorText)
WScript.Quit
End If
' archive@example.com is an envelope-only blind copy.
recipients = "editor@example.net,archive@example.com"
success = mail.SendMimeBd("updates@example.com",recipients,message)
If (success <> 1) Then
outFile.WriteLine(mail.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("SMTP relay accepted the signed message.")
success = mail.CloseSmtpConnection()
If (success <> 1) Then
outFile.WriteLine("The SMTP session did not close cleanly.")
End If
outFile.Close