Delphi DLL Requires Chilkat v11.0.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
mail: HCkMailMan;
email: HCkEmail;
message: HCkBinData;
privateKey: HCkPrivateKey;
signer: HCkDkim;
recipients: PWideChar;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
mail := CkMailMan_Create();
CkMailMan_putSmtpHost(mail,'smtp.example.com');
CkMailMan_putSmtpPort(mail,465);
CkMailMan_putSmtpSsl(mail,True);
CkMailMan_putRequireSslCertVerify(mail,True);
CkMailMan_putSmtpUsername(mail,'SMTP_USERNAME');
CkMailMan_putSmtpPassword(mail,'SMTP_PASSWORD');
email := CkEmail_Create();
CkEmail_putFrom(email,'Workshop team <updates@example.com>');
CkEmail_putSubject(email,'Workshop registration');
CkEmail_putBody(email,'Registration opens on Monday.');
success := CkEmail_AddTo(email,'Newsletter editor','editor@example.net');
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
// Render after all headers, recipients, and content are final.
message := CkBinData_Create();
success := CkMailMan_RenderToMimeBd(mail,email,message);
if (success <> True) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mail));
Exit;
end;
// Supply your RSA signing key. For an encrypted PEM, get its password from your credential store.
privateKey := CkPrivateKey_Create();
success := CkPrivateKey_LoadAnyFormatFile(privateKey,'dkim-private.pem','');
if (success <> True) then
begin
Memo1.Lines.Add(CkPrivateKey__lastErrorText(privateKey));
Exit;
end;
signer := CkDkim_Create();
CkDkim_putDkimDomain(signer,'example.com');
CkDkim_putDkimSelector(signer,'mail2026');
CkDkim_putDkimAlg(signer,'rsa-sha256');
success := CkDkim_SetDkimPrivateKey(signer,privateKey);
if (success <> True) then
begin
Memo1.Lines.Add(CkDkim__lastErrorText(signer));
Exit;
end;
success := CkDkim_DkimSign(signer,message);
if (success <> True) then
begin
Memo1.Lines.Add(CkDkim__lastErrorText(signer));
Exit;
end;
// archive@example.com is an envelope-only blind copy.
recipients := 'editor@example.net,archive@example.com';
success := CkMailMan_SendMimeBd(mail,'updates@example.com',recipients,message);
if (success <> True) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mail));
Exit;
end;
Memo1.Lines.Add('SMTP relay accepted the signed message.');
success := CkMailMan_CloseSmtpConnection(mail);
if (success <> True) then
begin
Memo1.Lines.Add('The SMTP session did not close cleanly.');
end;
CkMailMan_Dispose(mail);
CkEmail_Dispose(email);
CkBinData_Dispose(message);
CkPrivateKey_Dispose(privateKey);
CkDkim_Dispose(signer);