SQL Server Stored Procedure Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
FTP
HTML-to-XML
HTTP
MHT
MIME
RSA Encryption
Socket
Spider
String
Tar
Upload
XML
XMP
Zip

Byte Array
RSS
Atom
Self-Extractor

Create S/MIME Detached Signature with PFX

How to use a PFX to create a signed S/MIME message.

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)

    DECLARE @mime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @mime, 'UnlockComponent', @success OUT, 'Anything for 30-day trial'
    IF @success = 0
      BEGIN
        PRINT 'Failed to unlock component'
        RETURN
      END

    EXEC sp_OAMethod @mime, 'AddHeaderField', NULL, 'Subject', 'This is a test'
    EXEC sp_OAMethod @mime, 'AddHeaderField', NULL, 'Abc', '123'

    EXEC sp_OAMethod @mime, 'SetBodyFromPlainText', NULL, 'This is the body'

    DECLARE @certStore int
    EXEC @hr = sp_OACreate 'Chilkat.CertStore', @certStore OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @password nvarchar(4000)

    SELECT @password = 'myPassword'
    EXEC sp_OAMethod @certStore, 'LoadPfxFile', @success OUT, 'chilkat.pfx', @password
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @certStore, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    DECLARE @cert int

    EXEC sp_OAMethod @certStore, 'FindCertBySubjectCN', @cert OUT, 'Chilkat Software, Inc.'
    IF @cert Is NULL 
      BEGIN
        PRINT 'Failed to find certificate!'
        RETURN
      END

    --  Display the full distinguished name of the cert.
    EXEC sp_OAGetProperty @cert, 'SubjectDN', @sTmp0 OUT

    PRINT @sTmp0

    EXEC sp_OAMethod @mime, 'AddDetachedSignature', @success OUT, @cert
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0


END
GO

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2007 Chilkat Software, Inc. All Rights Reserved.