Sample code for 30+ languages & platforms
PowerBuilder

Get the Signer Certificate of a Signed Email

See more Email Object Examples

Demonstrates the Chilkat Email.LastSignerCert method, which copies the certificate for the signer at a given zero-based index into a Cert object. Most signed emails have one signer (index 0), but a message can have more than one. This example loads a signed email and reads the first signer's common name.

Background: Confirming that a signature is valid (see SignaturesValid) tells you the content wasn't altered, but not who signed it. LastSignerCert gives you the signer's certificate as an object so you can examine its subject and issuer and evaluate trust — an essential step before relying on a signature to establish the sender's identity.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Cert

li_Success = 0

//  Demonstrates the LastSignerCert method, which copies the certificate for the signer at
//  the given zero-based index into a Cert object.  Most signed emails have one signer
//  (index 0), but a message can have more than one.

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

li_Success = loo_Email.LoadEml("qa_data/eml/signed.eml")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

if loo_Email.ReceivedSigned = 1 then
    //  Get the certificate of the first signer (index 0).
    loo_Cert = create oleobject
    li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

    li_Success = loo_Email.LastSignerCert(0,loo_Cert)
    if li_Success = 1 then
        Write-Debug "Signer certificate (CN): " + loo_Cert.SubjectCN
    end if

end if

//  Note: The path "qa_data/..." is a relative local filesystem path,
//  relative to the current working directory of the running application.


destroy loo_Email
destroy loo_Cert