SmimeVerify Method
Verifies if the signature of the specified e-mail message is valid.

Namespace: MailBee.Security
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
public SmimeResult Verify(
	MailMessage message,
	MessageVerificationFlags flags,
	CertificateStore extraStore


Type: MailBee.MimeMailMessage
The message to be verified.
Type: MailBee.SecurityMessageVerificationFlags
A set of flags which specify the verification criteria.
Type: MailBee.SecurityCertificateStore
A reference to the certificate store containing additional certificates of the certification authorities, or a null reference (Nothing in Visual Basic) if only the system default certification authorities should be used for validating the certificate of the message signature.

Return Value

Type: SmimeResult
A reference to SmimeResult object containing either a bitwise combination of MessageVerificationFlags indicating which conditions of flags criteria have not been passed the verification or None if the verification completed successfully or the message was not signed.
MailBeeInvalidArgumentExceptionmessage is a null reference (Nothing in Visual Basic).

If the message has so-called "attached" signature, you'll need to check DecryptedMessage of the returned value of this method in order to get access to the original (unsigned) message. This is because messages with attached signatures look like encrypted messages so it's required to decode such a message (like in decryption procedure) to get access to the original message. Therefore checking the signature may also extract the original message from it. If DecryptedMessage is not set (null reference) in the returned value of this method, this means the message has so-called "detached" signature which is not encapsulated into the original message contents but simply added as attachment. In this case, message input parameter already refers to the original message and there is no need to extract anything.

extraStore usually needs to be set if the system default store lacks a certification authority which issued the certificate the message is signed with. This is common case for ASP.NET web applications because ASP.NET user has fewer certification authorities in its system default store than regular Windows users. See ASP.NET S/MIME Demo sample project shipped with MailBee for details.

To check the message verification result, examine VerificationResult property of the returned SmimeResult object. To access the signature certificate, use SignatureCertificate property of the same object.

To check if the original message had a digital signature, examine IsSigned property value of the original MailMessage object.

To decrypt and verify a message within a single method call, use DecryptAndVerify(MailMessage, MessageVerificationFlags) method or its overloads.

Note Note
This method can be slow in case if the certificate refers to a non-existing domain name (or local domain name while the current machine is not in that network).
This sample verifies the message signature using all the available criteria.
// 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();

    // Verify the message.
    SmimeResult smResult = objSmime.Verify(msg, MessageVerificationFlags.All, null);
    MessageVerificationFlags resultOptions = smResult.VerificationResult;
    // Check for the errors.
    if (resultOptions != MessageVerificationFlags.None)
        if ((resultOptions & MessageVerificationFlags.CertificateRevoked) == MessageVerificationFlags.CertificateRevoked)
            Console.WriteLine("Error! Certificate revoked...");
        if ((resultOptions & MessageVerificationFlags.MessageTampered) == MessageVerificationFlags.MessageTampered)
            Console.WriteLine("Error! Message has been tampered...");
        if ((resultOptions & MessageVerificationFlags.SignatureExpired) == MessageVerificationFlags.SignatureExpired)
            Console.WriteLine("Error! Signature expired...");
        if ((resultOptions & MessageVerificationFlags.SignerAndSenderDoNotMatch) == MessageVerificationFlags.SignerAndSenderDoNotMatch)
            Console.WriteLine("Error! Signer and sender do not match...");
        if ((resultOptions & MessageVerificationFlags.Untrusted) == MessageVerificationFlags.Untrusted)
            Console.WriteLine("Error! Untrusted certificate...");
    if (smResult.SignatureCertificate != null)
catch (MailBeeException ex)
See Also