Dkim SignerSign(Mime Message, IListHeader Id) Method
Digitally sign the message using a DomainKeys Identified Mail (DKIM) signature.
Definition
Namespace: MimeKit.Cryptography
Assembly: MimeKit.Cryptography (in MimeKit.Cryptography.dll) Version: 5.0.0
Assembly: MimeKit.Cryptography (in MimeKit.Cryptography.dll) Version: 5.0.0
C#
public void Sign(
MimeMessage message,
IList<HeaderId> headers
)Parameters
- message MimeMessage
- The message to sign.
- headers IListHeaderId
- The headers to sign.
Remarks
Digitally signs the message using a DomainKeys Identified Mail (DKIM) signature.
Example
C#
public static void DkimSign (MimeMessage message)
{
var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
var signer = new DkimSigner ("privatekey.pem", "example.com", "brisbane", DkimSignatureAlgorithm.RsaSha256) {
HeaderCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
BodyCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
AgentOrUserIdentifier = "@eng.example.com",
QueryMethod = "dns/txt",
};
// Prepare the message body to be sent over a 7bit transport (such as older versions of SMTP).
// Note: If the SMTP server you will be sending the message over supports the 8BITMIME extension,
// then you can use `EncodingConstraint.EightBit` instead.
message.Prepare (EncodingConstraint.SevenBit);
signer.Sign (message, headers);
}
Exceptions
| ArgumentNullException |
message is . -or- headers is . |
| ArgumentException |
headers does not contain the 'From' header. -or- headers contains one or more of the following headers: Return-Path, Received, Comments, Keywords, Bcc, Resent-Bcc, or DKIM-Signature. |