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

POP3 Verify Signed (S/MIME) Email

Demonstrates how to download and verify digitally signed S/MIME email.

Download Chilkat Email ActiveX

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

    --  Any string argument automatically begins the 30-day trial.
    DECLARE @success int

    EXEC sp_OAMethod @mailman, 'UnlockComponent', @success OUT, '30-day trial'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT

        PRINT @sTmp0
        RETURN
      END

    --  Set the POP3 server's hostname
    EXEC sp_OASetProperty @mailman, 'MailHost', 'mail.chilkatsoft.com'

    --  Set the POP3 login/password.
    EXEC sp_OASetProperty @mailman, 'PopUsername', 'myLogin'
    EXEC sp_OASetProperty @mailman, 'PopPassword', 'myPassword'

    DECLARE @sa int

    EXEC sp_OAMethod @mailman, 'GetUidls', @sa OUT
    IF @sa Is NULL 
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT

        PRINT @sTmp0
        RETURN
      END
    DECLARE @i int

    DECLARE @n int

    EXEC sp_OAGetProperty @sa, 'Count', @n OUT

    DECLARE @email int

    DECLARE @uidl nvarchar(4000)

    SELECT @i = 0
    WHILE @i <= @n - 1
      BEGIN

        EXEC sp_OAMethod @sa, 'GetString', @uidl OUT, @i

        EXEC sp_OAMethod @mailman, 'FetchEmail', @email OUT, @uidl
        IF @email Is NULL 
          BEGIN
            EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT

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

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

        PRINT @sTmp0

        --  The security layers of signed and/or encrypted emails
        --  are automatically "unwrapped" when loaded into
        --  a Chilkat email object.
        --  An application only needs to check to see if an email
        --  was received signed or encrypted, and then examine
        --  the success/failure.  For example:
        EXEC sp_OAGetProperty @email, 'ReceivedSigned', @sTmp0 OUT
        IF @sTmp0 = 1
          BEGIN


            PRINT 'This email was signed.'

            --  Check to see if the signatures were verified.
            EXEC sp_OAGetProperty @email, 'SignaturesValid', @sTmp0 OUT
            IF @sTmp0 = 1
              BEGIN

                PRINT 'Digital signature(s) verified.'


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

                PRINT 'Signer: ' + @sTmp0

                --  The certificate used for signing may be obtained
                --  by calling email.GetSignedByCert.
                DECLARE @cert int

                EXEC sp_OAMethod @email, 'GetSignedByCert', @cert OUT
                IF @cert Is NULL 
                  BEGIN

                    PRINT 'Failed to get signing certificate object.'
                  END
                ELSE
                  BEGIN

                    EXEC sp_OAGetProperty @cert, 'SubjectCN', @sTmp0 OUT

                    PRINT 'Signing cert: ' + @sTmp0

                  END

              END
            ELSE
              BEGIN

                PRINT 'Digital signature verification failed.'
              END

          END

        SELECT @i = @i + 1
      END

    EXEC sp_OAMethod @mailman, 'Pop3EndSession', NULL
END
GO

 

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