Click or drag to resize
MimeKit

MimeMessageSign Method (FormatOptions, DkimSigner, IListString, DkimCanonicalizationAlgorithm, DkimCanonicalizationAlgorithm)

Note: This API is now obsolete.

Digitally sign the message using a DomainKeys Identified Mail (DKIM) signature.

Namespace:  MimeKit
Assembly:  MimeKit (in MimeKit.dll) Version: 2.14.0
Syntax
C#
[ObsoleteAttribute("Use DkimSigner.Sign() instead.")]
public void Sign(
	FormatOptions options,
	DkimSigner signer,
	IList<string> headers,
	DkimCanonicalizationAlgorithm headerCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
	DkimCanonicalizationAlgorithm bodyCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple
)

Parameters

options
Type: MimeKitFormatOptions
The formatting options.
signer
Type: MimeKit.CryptographyDkimSigner
The DKIM signer.
headers
Type: System.Collections.GenericIListString
The list of header fields to sign.
headerCanonicalizationAlgorithm (Optional)
Type: MimeKit.CryptographyDkimCanonicalizationAlgorithm
The header canonicalization algorithm.
bodyCanonicalizationAlgorithm (Optional)
Type: MimeKit.CryptographyDkimCanonicalizationAlgorithm
The body canonicalization algorithm.
Exceptions
ExceptionCondition
ArgumentNullException

options is null.

-or-

signer is null.

-or-

headers is null.

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.

Remarks
Digitally signs the message using a DomainKeys Identified Mail (DKIM) signature.
Examples
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);
}
See Also