Sample code for 30+ languages & platforms
PowerBuilder

Provide a Certificate Vault to MailMan

See more POP3 Examples

Demonstrates the Chilkat MailMan.UseCertVault method, which provides an XML certificate vault to be searched for certificates and private keys when MailMan performs operations such as encryption, decryption, signing, or signature verification. This example builds a vault from a PFX, attaches it, and fetches a message that Chilkat can decrypt using the vault.

Background: A certificate vault is a portable, in-memory store of certificates and private keys. Rather than wiring up a specific certificate for each operation, you load your credentials into one XmlCertVault and hand it to MailMan, which then searches it automatically whenever a key is needed. This is especially useful on platforms without an OS certificate store, or when one application handles several identities.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Vault
oleobject loo_Email

li_Success = 0

//  Demonstrates the MailMan.UseCertVault method, which provides an XML certificate vault to
//  be searched for certificates and private keys when MailMan performs operations such as
//  encryption, decryption, signing, or signature verification.

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

//  Configure the POP3 server connection.
loo_Mailman.MailHost = "pop.example.com"
loo_Mailman.MailPort = 995
loo_Mailman.PopSsl = 1
loo_Mailman.PopUsername = "user@example.com"
loo_Mailman.PopPassword = "myPassword"

//  Build a certificate vault from a PFX (certificate + private key).
loo_Vault = create oleobject
li_rc = loo_Vault.ConnectToNewObject("Chilkat.XmlCertVault")

li_Success = loo_Vault.AddPfxFile("qa_data/certs/certs.pfx","pfx_password")
if li_Success = 0 then
    Write-Debug loo_Vault.LastErrorText
    destroy loo_Mailman
    destroy loo_Vault
    return
end if

//  Make the vault available to MailMan for crypto operations.
li_Success = loo_Mailman.UseCertVault(loo_Vault)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Vault
    return
end if

//  Fetch a message; Chilkat draws on the vault if a private key is needed to decrypt it.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")

li_Success = loo_Mailman.FetchOne(0,0,1,loo_Email)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Vault
    destroy loo_Email
    return
end if

Write-Debug "Decrypted = " + string(loo_Email.Decrypted)

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

//  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
//  connects and authenticates -- using the property settings above -- whenever a server
//  operation requires it.  Calling the explicit connect/authenticate methods can still be
//  helpful to determine whether a failure occurs while connecting or while authenticating.


destroy loo_Mailman
destroy loo_Vault
destroy loo_Email