SQL Server
SQL Server
Add a PFX Source to MailMan for Decryption
See more POP3 Examples
Demonstrates the Chilkat MailMan.AddPfxSourceFile method, which adds a PFX/PKCS#12 file to the MailMan object's internal list of sources used for locating certificates and private keys — for example, to decrypt S/MIME email downloaded from the server. The second argument is the PFX password. This example configures a POP3 connection and registers a PFX source.
Background: When
MailMan downloads an encrypted (S/MIME) message, it needs the recipient's private key to decrypt it. On Windows and macOS the OS certificate stores are searched automatically, but when the key lives in a standalone PFX file — common on Linux or in server deployments — AddPfxSourceFile tells MailMan where to find it. A PFX bundles the certificate and its private key in one password-protected file.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the MailMan.AddPfxSourceFile method, which adds a PFX/PKCS#12 file to the
-- MailMan object's internal list of sources used for locating certificates and private
-- keys (for example, to decrypt downloaded S/MIME email). The 2nd argument is the PFX
-- password.
DECLARE @mailman int
EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mailman OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Configure the POP3 server connection.
EXEC sp_OASetProperty @mailman, 'MailHost', 'pop.example.com'
EXEC sp_OASetProperty @mailman, 'MailPort', 995
EXEC sp_OASetProperty @mailman, 'PopSsl', 1
EXEC sp_OASetProperty @mailman, 'PopUsername', 'user@example.com'
EXEC sp_OASetProperty @mailman, 'PopPassword', 'myPassword'
-- Provide a PFX so that encrypted emails downloaded from the server can be decrypted.
EXEC sp_OAMethod @mailman, 'AddPfxSourceFile', @success OUT, 'qa_data/certs/decryption.pfx', 'pfx_password'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mailman
RETURN
END
PRINT 'Added the PFX certificate/private-key source.'
-- Note: The path "qa_data/certs/decryption.pfx" is a relative local filesystem path,
-- relative to the current working directory of the running application.
EXEC @hr = sp_OADestroy @mailman
END
GO