SmimeSignAndEncrypt Method
Signs and encrypts an e-mail message.

Namespace: MailBee.Security
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.3.0 build 647 for .NET 4.5
public MailMessage SignAndEncrypt(
	MailMessage message,
	Certificate signingCert,
	CertificateCollection encryptionCerts


Type: MailBee.MimeMailMessage
The original e-mail message to be signed and encrypted.
Type: MailBee.SecurityCertificate
The certificate to be used for signing the message. This certificate must contain a private key.
Type: MailBee.SecurityCertificateCollection
The collection of public certificates of all the recipients of the message.

Return Value

Type: MailMessage
A reference to the signed and encrypted message if the signing and encryption went successfully; a reference to the original message if it was already signed and encrypted; a null reference (Nothing in Visual Basic) if the signing or encryption failed.
MailBeeInvalidArgumentExceptionmessage or signingCert is a null reference (Nothing in Visual Basic) or encryptionCerts is a null reference or an empty collection.
MailBeeSmimeWin32ExceptionAn error occurred and ThrowExceptions is true.

See Sign(MailMessage, Certificate) and Encrypt(MailMessage, CertificateCollection) topics for details on signing and encryption process.

If you have the signing certificate as an X509Certificate2 object, you can use Certificate(X509Certificate2) constructor to create Certificate object from it.

If you have the encryption certificates as an X509Certificate2Collection object, you can use FromX509Certificate2Collection(X509Certificate2Collection) method to create CertificateCollection object from it.

This sample signs and encrypts a message.
// 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();

Smime objSmime = new Smime();

    // Search for the sender certificate in the system certificate store.
    CertificateStore myStore = new CertificateStore(CertificateStore.Personal, CertStoreType.System, null);
    CertificateCollection signingCerts = myStore.FindCertificates("", CertificateFields.EmailAddress);
    Certificate signingCert = null;
    if (signingCerts.Count > 0) signingCert = signingCerts[0];

    // Get the recipients certificates from the the system certificate store.
    CertificateCollection encryptionCerts = new CertificateStore(CertificateStore.OtherPeople, CertStoreType.System, null).GetAllCertificates();

    // Sign and encrypt the message.
    MailMessage signEncMsg = objSmime.SignAndEncrypt(msg, signingCert, encryptionCerts);

    // Save the resulting message.
catch (MailBeeException ex)
See Also