Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

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

Visual FoxPro
LOCAL lnSuccess
LOCAL loMail
LOCAL loEmail
LOCAL loMessage
LOCAL loPrivateKey
LOCAL loSigner
LOCAL lcRecipients

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.

loMail = CreateObject('Chilkat.MailMan')
loMail.SmtpHost = "smtp.example.com"
loMail.SmtpPort = 465
loMail.SmtpSsl = 1
loMail.RequireSslCertVerify = 1
loMail.SmtpUsername = "SMTP_USERNAME"
loMail.SmtpPassword = "SMTP_PASSWORD"
loEmail = CreateObject('Chilkat.Email')
loEmail.From = "Workshop team <updates@example.com>"
loEmail.Subject = "Workshop registration"
loEmail.Body = "Registration opens on Monday."
lnSuccess = loEmail.AddTo("Newsletter editor","editor@example.net")
IF (lnSuccess <> 1) THEN
    ? loEmail.LastErrorText
    RELEASE loMail
    RELEASE loEmail
    CANCEL
ENDIF

*  Render after all headers, recipients, and content are final.
loMessage = CreateObject('Chilkat.BinData')
lnSuccess = loMail.RenderToMimeBd(loEmail,loMessage)
IF (lnSuccess <> 1) THEN
    ? loMail.LastErrorText
    RELEASE loMail
    RELEASE loEmail
    RELEASE loMessage
    CANCEL
ENDIF

*  Supply your RSA signing key. For an encrypted PEM, get its password from your credential store.
loPrivateKey = CreateObject('Chilkat.PrivateKey')
lnSuccess = loPrivateKey.LoadAnyFormatFile("dkim-private.pem","")
IF (lnSuccess <> 1) THEN
    ? loPrivateKey.LastErrorText
    RELEASE loMail
    RELEASE loEmail
    RELEASE loMessage
    RELEASE loPrivateKey
    CANCEL
ENDIF

loSigner = CreateObject('Chilkat.Dkim')
loSigner.DkimDomain = "example.com"
loSigner.DkimSelector = "mail2026"
loSigner.DkimAlg = "rsa-sha256"
lnSuccess = loSigner.SetDkimPrivateKey(loPrivateKey)
IF (lnSuccess <> 1) THEN
    ? loSigner.LastErrorText
    RELEASE loMail
    RELEASE loEmail
    RELEASE loMessage
    RELEASE loPrivateKey
    RELEASE loSigner
    CANCEL
ENDIF

lnSuccess = loSigner.DkimSign(loMessage)
IF (lnSuccess <> 1) THEN
    ? loSigner.LastErrorText
    RELEASE loMail
    RELEASE loEmail
    RELEASE loMessage
    RELEASE loPrivateKey
    RELEASE loSigner
    CANCEL
ENDIF

*  archive@example.com is an envelope-only blind copy.
lcRecipients = "editor@example.net,archive@example.com"
lnSuccess = loMail.SendMimeBd("updates@example.com",lcRecipients,loMessage)
IF (lnSuccess <> 1) THEN
    ? loMail.LastErrorText
    RELEASE loMail
    RELEASE loEmail
    RELEASE loMessage
    RELEASE loPrivateKey
    RELEASE loSigner
    CANCEL
ENDIF

? "SMTP relay accepted the signed message."
lnSuccess = loMail.CloseSmtpConnection()
IF (lnSuccess <> 1) THEN
    ? "The SMTP session did not close cleanly."
ENDIF

RELEASE loMail
RELEASE loEmail
RELEASE loMessage
RELEASE loPrivateKey
RELEASE loSigner