B4X Requires Chilkat v11.8.0+
B4X
Add a PEM Source of Certificates and Private Keys to MailMan
See more POP3 Examples
Demonstrates the Chilkat MailMan.AddPemSource method, which adds the certificates and private keys of a Pem object to the sources MailMan searches for certificates and private keys when it decrypts S/MIME email or verifies signatures. This example loads a PEM file into a Pem object, adds it, and fetches a message that Chilkat can decrypt with it.
Background: A
Pem object is an in-memory collection of certificates and private keys. Rather than wiring up a specific certificate for each operation, you load your credentials into a Pem object and hand it to MailMan, which then searches its certificates automatically whenever a key is needed. This is especially useful on platforms without an OS certificate store, or when one application handles several identities. AddPemSource can be called multiple times. Each call adds more certificates to the ones already added. AddPemSource was added in Chilkat v11.8.0 and replaces UseCertVault and the AddPfxSource methods.Chilkat B4X Downloads
Dim success As Boolean = False
' Demonstrates the MailMan.AddPemSource method, which adds the certificates and private keys
' of a Pem object to the sources MailMan searches for certificates and private keys when it
' decrypts S/MIME email or verifies signatures.
Dim mailman As ChilkatMailMan
mailman.Initialize("mailman")
' Configure the POP3 server connection.
mailman.MailHost = "pop.example.com"
mailman.MailPort = 995
mailman.PopSsl = True
mailman.PopUsername = "user@example.com"
mailman.PopPassword = "myPassword"
' Load a PEM file (certificate + private key) into a Pem object. The 2nd argument of LoadPemFile
' is the password of the private key. (Pass an empty string if the private key is not encrypted.)
Dim pem As ChilkatPem
pem.Initialize
success = pem.LoadPemFile("qa_data/certs/certs.pem", "pem_password")
If success = False Then
Log(pem.LastErrorText)
Return
End If
' Make the certificates and private keys available to MailMan.
' AddPemSource can be called multiple times. Each call adds more certificates to the ones already added.
success = mailman.AddPemSource(pem)
If success = False Then
Log(mailman.LastErrorText)
Return
End If
' Fetch a message; Chilkat draws on the added certificates if a private key is needed to decrypt it.
Dim email As ChilkatEmail
email.Initialize
success = mailman.FetchOne(False, 0, 1, email)
If success = False Then
Log(mailman.LastErrorText)
Return
End If
Log("Decrypted = " & email.Decrypted)
' Note: The path "qa_data/certs/certs.pem" 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.