Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

-- 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.

local mailman = chilkat.MailMan.new()

-- Configure the POP3 server connection.
mailman.mail_host = "pop.example.com"
mailman.mail_port = 995
mailman.pop_ssl = true
mailman.pop_username = "user@example.com"
mailman.pop_password = "myPassword"

-- Build a certificate vault from a PFX (certificate + private key).
local vault = chilkat.XmlCertVault.new()
local success = vault:add_pfx_file("qa_data/certs/certs.pfx", "pfx_password")
if not success then
    print(vault.last_error_text)
    return
end

-- Make the vault available to MailMan for crypto operations.
success = mailman:use_cert_vault(vault)
if not success then
    print(mailman.last_error_text)
    return
end

-- Fetch a message; Chilkat draws on the vault if a private key is needed to decrypt it.
local email = chilkat.Email.new()
success = mailman:fetch_one(false, 0, 1, email)
if not success then
    print(mailman.last_error_text)
    return
end

print("Decrypted = " .. tostring(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.