DataFlex
DataFlex
Add a PFX Source to MailMan from BinData
See more POP3 Examples
Demonstrates the Chilkat MailMan.AddPfxSourceBd method, which adds a PFX/PKCS#12 certificate store to the MailMan object's internal list of sources used for locating certificates and private keys. The first argument is a BinData containing the PFX bytes and the second is the PFX password. This example loads a PFX into a BinData, registers it, and fetches a message Chilkat can decrypt.
Background: This is the in-memory (
BinData) counterpart to AddPfxSourceFile. It is the right choice when the PFX bytes come from somewhere other than a file — a database, a secrets manager, or an HTTPS download — letting you supply the certificate and private key without first writing sensitive key material to disk.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
Variant vBdPfx
Handle hoBdPfx
Variant vEmail
Handle hoEmail
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates the MailMan.AddPfxSourceBd method, which adds a PFX/PKCS#12 certificate store
// to the MailMan object's internal list of sources used for locating certificates and
// private keys. The 1st argument is a BinData containing the PFX bytes and the 2nd is the
// PFX password.
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Configure the POP3 server connection.
Set ComMailHost Of hoMailman To "pop.example.com"
Set ComMailPort Of hoMailman To 995
Set ComPopSsl Of hoMailman To True
Set ComPopUsername Of hoMailman To "user@example.com"
Set ComPopPassword Of hoMailman To "myPassword"
// Load the PFX bytes into a BinData (they could come from a file, database, or secrets store).
Get Create (RefClass(cComChilkatBinData)) To hoBdPfx
If (Not(IsComObjectCreated(hoBdPfx))) Begin
Send CreateComObject of hoBdPfx
End
Get ComLoadFile Of hoBdPfx "qa_data/certs/decryption.pfx" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoBdPfx To sTemp1
Showln sTemp1
Procedure_Return
End
// Add the PFX as a source of certificates and private keys.
Get pvComObject of hoBdPfx to vBdPfx
Get ComAddPfxSourceBd Of hoMailman vBdPfx "pfx_password" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
// Fetch a message; if it is encrypted, Chilkat can decrypt it using the PFX source.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Get pvComObject of hoEmail to vEmail
Get ComFetchOne Of hoMailman False 0 1 vEmail To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComDecrypted Of hoEmail To bTemp1
Showln "Decrypted = " bTemp1
// Note: The path "qa_data/certs/decryption.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.
End_Procedure