Sample code for 30+ languages & platforms
PowerBuilder

Add a PFX Source File for S/MIME Decryption

See more IMAP Examples

Demonstrates the Chilkat Imap.AddPfxSourceFile method, which adds a PFX file as a source of certificates and private keys for S/MIME processing. The first argument is the PFX file path and the second is its password. Call it once for each additional source.

Note: The certificate path is relative to the application's current working directory. Supply the path to your own certificate file.

Background: This is the file-based form of AddPfxSourceBd. Registering the private keys needed to decrypt S/MIME mail lets Chilkat decrypt messages transparently during fetch. Add several sources if recipients' keys are spread across multiple PFX files. On Windows and macOS the system stores (and Keychain) are searched automatically in addition to the sources you add.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
string ls_PfxPassword

li_Success = 0

//  Demonstrates the Imap.AddPfxSourceFile method, which adds a PFX file as a source of
//  certificates and private keys for S/MIME decryption.  The 1st argument is the PFX file path
//  and the 2nd is its password.

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

loo_Imap.Ssl = 1
loo_Imap.Port = 993

li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

//  The PFX password is not hard-coded in source.  Insert code here to obtain it from an
//  interactive prompt, environment variable, or a secrets vault.

//  Add the PFX file as a source for S/MIME certificates and private keys.  Call once per source.
li_Success = loo_Imap.AddPfxSourceFile("qa_data/smime.pfx",ls_PfxPassword)
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

//  Messages downloaded after this are automatically decrypted when a matching key is found.

li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if



destroy loo_Imap