Signs the current e-mail message with DKIM and classic DomainKeys signatures.
If you need more advanced level of DomainKeys/DKIM signing or additional information on private keys, certificates and so on, refer to DomainKeys class.
Moreover, in ideal case it should be your your mail server's job to sign outgoing e-mails with DomainKeys/DKIM signatures. Use MailBee only if you cannot enable this feature on your mail server.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | privateKeyStr or selector is a null reference (Nothing in Visual Basic) or the message to be signed does not include the header specifying the sender (Sender or From header) or headersToSign array (if not null) does not list the name of that header or the sender's e-mail address domain is empty. |
| MailBeeException | An error occurred and ThrowExceptions is true. |
This sample composes a simple e-mail, signs it with DomainKeys and DKIM signatures and sends it out. We assume the private certificate is in "C:\Temp\rsa512.private" file and the domain selector is "dk".
[C#] using System; using MailBee; using MailBee.Mime; using MailBee.SmtpMail; using MailBee.Security; class Sample { static void Main(string[] args) { // Initialize mailer. Smtp mailer = new Smtp(); // Set the message properties. mailer.Message.From.Email = "john.doe@company.com"; mailer.Message.To.Add("jane.doe@example.com"); mailer.Message.Subject = "Hello"; mailer.Message.BodyPlainText = "Hello, Jane, can we meet today?"; // Sign the message with DomainKeys and DKIM. mailer.Message.DomainKeysSign(false, null, @"C:\Temp\rsa512.private", true, "dk", DomainKeysTypes.Both); // Send the message via SMTP server (authentication is used in this sample). mailer.SmtpServers.Add("mail.company.com", "john.doe@company.com", "secret"); mailer.Send(); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.Mime Imports MailBee.SmtpMail Imports MailBee.Security Class Sample Shared Sub Main(ByVal args() As String) ' Initialize mailer. Dim mailer As Smtp = New Smtp() ' Set the message properties. mailer.Message.From.Email = "john.doe@company.com" mailer.Message.To.Add("jane.doe@example.com"") mailer.Message.Subject = "Hello" mailer.Message.BodyPlainText = "Hello, Jane, can we meet today?" ' Sign the message with DomainKeys and DKIM. mailer.Message.DomainKeysSign(False, Nothing, "C:\Temp\rsa512.private", True, "dk", DomainKeysTypes.Both) ' Send the message via SMTP server (authentication is used in this sample). mailer.SmtpServers.Add("mail.company.com", "john.doe@company.com", "secret") mailer.Send() End Sub End Class
MailMessage Class | MailBee.Mime Namespace | DomainKeys