DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoImap
String sPfxPassword
String sTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatImap)) To hoImap
If (Not(IsComObjectCreated(hoImap))) Begin
Send CreateComObject of hoImap
End
Set ComSsl Of hoImap To True
Set ComPort Of hoImap To 993
Get ComConnect Of hoImap "imap.example.com" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Get ComAddPfxSourceFile Of hoImap "qa_data/smime.pfx" sPfxPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
// Messages downloaded after this are automatically decrypted when a matching key is found.
Get ComDisconnect Of hoImap To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure