SmimeSign Method
Signs an e-mail message with a digital signature.

Namespace: MailBee.Security
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public MailMessage Sign(
	MailMessage message,
	Certificate signingCert
)

Parameters

message
Type: MailBee.MimeMailMessage
The original e-mail message to be signed.
signingCert
Type: MailBee.SecurityCertificate
The certificate to be used for signing the message. This certificate must contain a private key.

Return Value

Type: MailMessage
A reference to the signed message if the signing went successfully; a reference to the original message if it was already signed; a null reference (Nothing in Visual Basic) if the signing process failed.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionmessage or signingCert is a null reference (Nothing in Visual Basic).
MailBeeSmimeWin32ExceptionAn error occurred and ThrowExceptions is true.
Remarks

Make sure the Certificate used for signing has the same EmailAddress as Email value of MailMessage.From of the message being signed. Otherwise, the message will still be signed successfully but it might not be trusted by its recipients when it gets delivered.

To create a signature, MailBee uses HashAlgorithm and the private key of signingCert to calculate a hash of the message data.

The developer can also use the SignAndEncrypt(MailMessage, Certificate, CertificateCollection) method to sign and encrypt a message within a single method call.

Examples
The following sample loads the message from disk, signs it with the sender's certificate, and saves it back to disk.
// To use the code below, import these namespace at the top of your code
using System;
using MailBee;
using MailBee.Mime;
using MailBee.Security;

// The actual code (put it into a method of your class)

// Load the message from file.
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\original.eml");

Smime objSmime = new Smime();

try
{
    // Load certificate from the specified file.
    Certificate signingCert = new Certificate(@"C:\Docs\cert.pfx", CertFileType.Pfx, "secret");
    // Sign the message.
    MailMessage signMsg = objSmime.Sign(msg, signingCert);
    // Save the signed message to disk.
    signMsg.SaveMessage(@"C:\Docs\signed.eml");
    Console.WriteLine("Done.");
}
catch (MailBeeException ex)
{
    Console.WriteLine(ex.Message);
}
See Also