SQL Server Stored Procedure Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
DKIM / DomainKey
FTP
HTML Conversion
HTTP
MHT
MIME
NTLM
RSA
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Amazon S3
Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

Search/Download only Encrypted Emails

Searching an IMAP mailbox for emails that are encrypted and download. Emails are automatically decrypted.

Download 32-bit Chilkat IMAP ActiveX (.msi)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @imap int
    EXEC @hr = sp_OACreate 'Chilkat.Imap', @imap OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  Anything unlocks the component and begins a fully-functional 30-day trial.
    EXEC sp_OAMethod @imap, 'UnlockComponent', @success OUT, 'Anything for 30-day trial'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  Connect to an IMAP server.
    EXEC sp_OAMethod @imap, 'Connect', @success OUT, 'www.cknotes.com'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  Login
    EXEC sp_OAMethod @imap, 'Login', @success OUT, 'myLogin', 'myPassword'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  Select an IMAP mailbox
    EXEC sp_OAMethod @imap, 'SelectMailbox', @success OUT, 'Inbox'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  An S/MIME encrypted email should have a content-type
    --  header containing the substring "pkcs7-mime":
    DECLARE @headerSearch nvarchar(4000)

    SELECT @headerSearch = 'HEADER Content-Type pkcs7-mime'

    DECLARE @messageSet int

    DECLARE @fetchUids int

    SELECT @fetchUids = 1
    EXEC sp_OAMethod @imap, 'Search', @messageSet OUT, @headerSearch, @fetchUids
    IF @messageSet Is NULL 
      BEGIN
        EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  Download the emails indicated in the messageSet.
    --  The emails are automatically decrypted.
    DECLARE @bundle int

    EXEC sp_OAMethod @imap, 'FetchBundle', @bundle OUT, @messageSet
    IF @bundle Is NULL 
      BEGIN

        EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  Display some information from each email:
    DECLARE @i int

    EXEC sp_OAGetProperty @bundle, 'MessageCount', @iTmp0 OUT
    SELECT @i = 0
    WHILE @i <= @iTmp0 - 1
      BEGIN
        DECLARE @email int

        EXEC sp_OAMethod @bundle, 'GetEmail', @email OUT, @i

        EXEC sp_OAMethod @email, 'GetHeaderField', @sTmp0 OUT, 'Date'
        PRINT @sTmp0
        EXEC sp_OAGetProperty @email, 'Subject', @sTmp0 OUT

        PRINT @sTmp0
        EXEC sp_OAGetProperty @email, 'From', @sTmp0 OUT

        PRINT @sTmp0


        EXEC sp_OAGetProperty @email, 'ReceivedEncrypted', @sTmp0 OUT

        PRINT 'Received Encrypted: ' + @sTmp0
        EXEC sp_OAGetProperty @email, 'ReceivedEncrypted', @sTmp0 OUT
        IF @sTmp0 = 1
          BEGIN

            EXEC sp_OAGetProperty @email, 'Decrypted', @sTmp0 OUT

            PRINT 'Successfully Decrypted: ' + @sTmp0
          END


        EXEC sp_OAGetProperty @email, 'ReceivedSigned', @sTmp0 OUT

        PRINT 'Received Signed: ' + @sTmp0
        EXEC sp_OAGetProperty @email, 'ReceivedSigned', @sTmp0 OUT
        IF @sTmp0 = 1
          BEGIN

            EXEC sp_OAGetProperty @email, 'SignaturesValid', @sTmp0 OUT

            PRINT 'Signature Verified: ' + @sTmp0
          END


        PRINT '--'

        SELECT @i = @i + 1
      END

    --  Disconnect from the IMAP server.
    EXEC sp_OAMethod @imap, 'Disconnect', NULL


END
GO

 

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