Sample code for 30+ languages & platforms
PowerShell

Check if a MIME Entity is Encrypted (S/MIME)

See more MIME Examples

Demonstrates the Chilkat Mime.IsEncrypted method, which returns whether the entity is a CMS/PKCS #7 encrypted S/MIME wrapper. It takes no arguments.

Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.

Background: This tells you a message is encrypted and must be decrypted before its real content is available — the trigger for supplying a recipient certificate and private key to Decrypt. Reading the body without decrypting first would just yield the opaque PKCS #7 blob.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Demonstrates the Mime.IsEncrypted method, which returns whether the entity is a CMS/PKCS #7 encrypted S/MIME wrapper.  It takes no arguments.

$mime = New-Object Chilkat.Mime
$success = $mime.LoadMimeFile("qa_data/encrypted.eml")
if ($success -eq $false) {
    $($mime.LastErrorText)
    exit
}

if ($mime.IsEncrypted()) {
    $("This is an encrypted S/MIME message.")
}
else {
    $("This is not an encrypted S/MIME message.")
}