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

SSL POP3 with Certificates

Demonstrates how to use a client-side certificate with an SSL connection to a POP3 server. Also demonstrates how to get the POP3 server's SSL certificate.

Download Chilkat Email ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    --  The mailman object is used for receiving (POP3)
    --  and sending (SMTP) email.
    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
        PRINT 'Component unlock failed'
        RETURN
      END

    --  Set the GMail account POP3 properties.
    EXEC sp_OASetProperty @mailman, 'MailHost', 'pop.gmail.com'
    EXEC sp_OASetProperty @mailman, 'PopUsername', 'chilkat.support'
    EXEC sp_OASetProperty @mailman, 'PopPassword', '****'
    EXEC sp_OASetProperty @mailman, 'PopSsl', 1
    EXEC sp_OASetProperty @mailman, 'MailPort', 995

    --  Use our certificate, which is already installed
    --  in our current-user certificate store on the computer.
    DECLARE @clientCert int
    EXEC @hr = sp_OACreate 'Chilkat.Cert', @clientCert OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @clientCert, 'LoadByCommonName', @success OUT, 'Chilkat Software, Inc.'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @clientCert, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END
    --  Note: The GMail POP3 server does not require that you
    --  have a client cert.  This example only demonstrates
    --  how you may use a client certificate.  Typically,
    --  higher-security systems may require a client-side SSL cert.
    EXEC sp_OAMethod @mailman, 'SetSslClientCert', NULL, @clientCert

    --  Establish a POP3 connection:
    EXEC sp_OAMethod @mailman, 'Pop3BeginSession', @success OUT
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END
    --  Let's look at the LastErrorText to see the details
    --  of the successful connection.  We should see our cert:
    EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT

    PRINT @sTmp0

    --  OK, now examine the server's cert:
    DECLARE @serverCert int

    EXEC sp_OAMethod @mailman, 'GetPop3SslServerCert', @serverCert OUT
    IF @serverCert Is NULL 
      BEGIN
        PRINT 'No server cert available.'
      END
    ELSE
      BEGIN

        PRINT 'Server SSL certificate:'
        EXEC sp_OAGetProperty @serverCert, 'SubjectDN', @sTmp0 OUT

        PRINT @sTmp0

        --  Was the server certificate verified?
        --  It's not necessarily an error if the SSL Server cert is not verified.
        EXEC sp_OAGetProperty @mailman, 'Pop3SslServerCertVerified', @sTmp0 OUT
        IF @sTmp0 = 1
          BEGIN

            PRINT 'Server SSL certificate was verified.'
          END
        ELSE
          BEGIN

            PRINT 'Server SSL certificate was NOT verified!'
          END
      END


END
GO

 

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

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