Sample code for 30+ languages & platforms
Tcl

Use an XML Certificate Vault with IMAP

See more IMAP Examples

Demonstrates the Chilkat Imap.UseCertVault method, which associates an XmlCertVault with the Imap object as a source of certificates and private keys for S/MIME operations. The only argument is the vault. Only one vault is associated at a time.

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

Background: An XmlCertVault is a portable container that can hold multiple certificates and keys in a single (optionally password-protected) XML file. It is a convenient way to ship the exact set of credentials an application needs without depending on the operating system's certificate stores. Associating a vault makes all of its contents available for S/MIME decryption and signature verification.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Imap.UseCertVault method, which associates an XmlCertVault with the Imap
#  object as a source of certificates and private keys for S/MIME operations.  The only
#  argument is the XmlCertVault.

set imap [new_CkImap]

CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993

set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

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

#  Build a certificate vault and add a PFX to it.
set vault [new_CkXmlCertVault]

set success [CkXmlCertVault_AddPfxFile $vault "qa_data/smime.pfx" $pfxPassword]
if {$success == 0} then {
    puts [CkXmlCertVault_lastErrorText $vault]
    delete_CkImap $imap
    delete_CkXmlCertVault $vault
    exit
}

#  Associate the vault with the Imap object.  Only one vault is associated at a time.
set success [CkImap_UseCertVault $imap $vault]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    delete_CkXmlCertVault $vault
    exit
}

set success [CkImap_Disconnect $imap]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    delete_CkXmlCertVault $vault
    exit
}


delete_CkImap $imap
delete_CkXmlCertVault $vault