SmimeSignAndEncrypt Method |
Signs and encrypts an e-mail message.
Namespace: MailBee.SecurityAssembly: MailBee.NET.45 (in MailBee.NET.45.dll) Version: 10.0.45.502
Syntaxpublic MailMessage SignAndEncrypt(
MailMessage message,
Certificate signingCert,
CertificateCollection encryptionCerts
)
Public Function SignAndEncrypt (
message As MailMessage,
signingCert As Certificate,
encryptionCerts As CertificateCollection
) As MailMessage
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. - encryptionCerts
- Type: MailBee.SecurityCertificateCollection
The collection of public certificates of all the recipients of the message.
Return Value
Type:
MailMessageA 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
Remarks
ExamplesThis sample signs and encrypts a message.
using System;
using MailBee;
using MailBee.Mime;
using MailBee.Security;
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Temp\original.eml");
Smime objSmime = new Smime();
try
{
CertificateStore myStore = new CertificateStore(CertificateStore.Personal, CertStoreType.System, null);
CertificateCollection signingCerts = myStore.FindCertificates("user@afterlogic.com", CertificateFields.EmailAddress);
Certificate signingCert = null;
if (signingCerts.Count > 0) signingCert = signingCerts[0];
CertificateCollection encryptionCerts = new CertificateStore(CertificateStore.OtherPeople, CertStoreType.System, null).GetAllCertificates();
MailMessage signEncMsg = objSmime.SignAndEncrypt(msg, signingCert, encryptionCerts);
signEncMsg.SaveMessage(@"C:\Temp\result.eml");
}
catch (MailBeeException ex)
{
Console.WriteLine(ex.Message);
}
Imports MailBee
Imports MailBee.Mime
Imports MailBee.Security
Dim msg As MailMessage = New MailMessage
msg.LoadMessage("C:\Temp\original.eml")
Dim objSmime As Smime = New Smime
Try
Dim myStore As CertificateStore = New CertificateStore(CertificateStore.Personal, CertStoreType.System, Nothing)
Dim signingCerts As CertificateCollection = myStore.FindCertificates("user@afterlogic.com", CertificateFields.EmailAddress)
Dim signingCert As Certificate = Nothing
If (signingCerts.Count > 0) Then
signingCert = signingCerts(0)
End If
Dim encryptionCerts As CertificateCollection = New CertificateStore(CertificateStore.OtherPeople, CertStoreType.System, Nothing).GetAllCertificates()
Dim signEncMsg As MailMessage = objSmime.SignAndEncrypt(msg, signingCert, encryptionCerts)
signEncMsg.SaveMessage("C:\Temp\result.eml")
Catch ex As MailBeeException
Console.WriteLine(ex.Message)
End Try
See Also