SmimeSignAndEncrypt Method
Signs and encrypts an e-mail message.

Namespace: MailBee.Security
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 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.
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