Sample code for 30+ languages & platforms
PowerBuilder

Check if a Received Email Was Decrypted

See more Email Object Examples

Demonstrates the read-only Chilkat Email.Decrypted property, which is true if the email arrived encrypted and was successfully decrypted. This property is only meaningful when ReceivedEncrypted is true, so you should always check ReceivedEncrypted first — a false value can mean either that the message was not encrypted or that decryption did not succeed. This example loads a received email and reports its encryption/decryption status.

Background: Encrypted email typically uses S/MIME. The sender encrypts the message with the recipient's public-key certificate, and only the holder of the matching private key can decrypt it. When Chilkat loads such a message and has access to the private key, it decrypts automatically; ReceivedEncrypted tells you the message arrived encrypted, and Decrypted tells you whether decryption succeeded.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email

li_Success = 0

//  Demonstrates the Email.Decrypted property.
//  Decrypted is true if the email arrived encrypted and was successfully
//  decrypted.  It is only meaningful when ReceivedEncrypted is true.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Load an email that was received (from a .eml file).
li_Success = loo_Email.LoadEml("qa_data/eml/received.eml")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

//  Always check ReceivedEncrypted first.
if loo_Email.ReceivedEncrypted = 1 then
    if loo_Email.Decrypted = 1 then
        Write-Debug "The email was encrypted and was successfully decrypted."
    else
        Write-Debug "The email was encrypted but could NOT be decrypted."
    end if

else
    Write-Debug "The email did not arrive encrypted."
end if



destroy loo_Email