Unicode C++
Unicode C++
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 Unicode C++ Downloads
#include <CkImapW.h>
#include <CkXmlCertVaultW.h>
void ChilkatSample(void)
{
bool success = false;
// 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.
CkImapW imap;
imap.put_Ssl(true);
imap.put_Port(993);
success = imap.Connect(L"imap.example.com");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.Login(L"user@example.com",L"myPassword");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// 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.
const wchar_t *pfxPassword = 0;
// Build a certificate vault and add a PFX to it.
CkXmlCertVaultW vault;
success = vault.AddPfxFile(L"qa_data/smime.pfx",pfxPassword);
if (success == false) {
wprintf(L"%s\n",vault.lastErrorText());
return;
}
// Associate the vault with the Imap object. Only one vault is associated at a time.
success = imap.UseCertVault(vault);
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}