SmimeSignAndEncrypt Method (MailMessage, Certificate, CertificateCollection, CertificateCollection)
Signs and encrypts an e-mail message, with the ability to provide a user-defined chain of signing certificates.

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

Parameters

message
Type: MailBee.MimeMailMessage
The original e-mail message to be signed and encrypted.
signingCert
Type: MailBee.SecurityCertificate
The certificate to be used for signing the message. This certificate must contain a private key.
extraSigningCerts
Type: MailBee.SecurityCertificateCollection
The additional certificates in the chain of the signing certificate. If a null reference (Nothing in Visual Basic), MailBee will build the certificate chain from the signing certificate to the root authority automatically.
encryptionCerts
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.
Exceptions
ExceptionCondition
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.
Remarks
This is a special overload which makes it possible to sign e-mail messages with certificate whose root authority certificate is not present in the system store. In this case, extraSigningCerts collection must contain all certificates signingCert derives from (such as root authority and CA certificates).
Examples
For a generic example of sign+encrypt, see SignAndEncrypt(MailMessage, Certificate, CertificateCollection) topic. To learn how to supply extra certificates for signing, see Sign(MailMessage, Certificate, CertificateCollection) topic.
See Also