DataFlex
DataFlex
Set the Decryption Certificate for MailMan
See more POP3 Examples
Demonstrates the Chilkat MailMan.SetDecryptCert method, which explicitly specifies the certificate to use when decrypting encrypted email. The certificate must correspond to the recipient certificate used to encrypt the message and must have access to its private key. This example loads the certificate from a PFX, registers it, and fetches a message that Chilkat can then decrypt.
Background: Decrypting S/MIME mail requires the recipient's private key, so the certificate you supply must carry it — which is why a PFX (certificate + private key in one password-protected file) is used here. Chilkat can find installed certificates automatically on Windows and macOS;
SetDecryptCert is how you point it at a specific one instead. If the certificate and key live in separate files, use SetDecryptCert2.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
Variant vCert
Handle hoCert
Variant vEmail
Handle hoEmail
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates the MailMan.SetDecryptCert method, which explicitly specifies the certificate
// to use when decrypting encrypted email. The certificate must correspond to the recipient
// certificate used to encrypt the message, and must have access to its private key.
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 certificate together with its private key from a PFX file.
Get Create (RefClass(cComChilkatCert)) To hoCert
If (Not(IsComObjectCreated(hoCert))) Begin
Send CreateComObject of hoCert
End
Get ComLoadPfxFile Of hoCert "qa_data/certs/decryption.pfx" "pfx_password" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoCert To sTemp1
Showln sTemp1
Procedure_Return
End
// Specify the certificate to use when decrypting downloaded email.
Get pvComObject of hoCert to vCert
Get ComSetDecryptCert Of hoMailman vCert 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 decrypts it using this certificate.
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 ComReceivedEncrypted Of hoEmail To bTemp1
Showln "ReceivedEncrypted = " bTemp1
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