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

Create Multipart/Alternative MIME

Create a simple multipart/alternative 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'
        RETURN
      END

    --  Make this a multipart/alternative MIME message:
    EXEC sp_OAMethod @mime, 'NewMultipartAlternative', NULL

    --  Create a plain-text part and add it to the multipart/alternative MIME.
    DECLARE @ptMime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @ptMime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @ptMime, 'SetBodyFromPlainText', NULL, 'This is the plain-text body'
    EXEC sp_OAMethod @mime, 'AppendPart', NULL, @ptMime

    --  Now do the same for HTML:
    DECLARE @htMime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @htMime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @htMime, 'SetBodyFromHtml', NULL, '<html><body>This is the HTML body</body></html>'
    EXEC sp_OAMethod @mime, 'AppendPart', NULL, @htMime

    --  Show the full multipart/alternative MIME text which includes both parts:
    EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0

    --  Need to change the boundary string?
    EXEC sp_OASetProperty @mime, 'Boundary', '__NewBoundaryString__123'

    --  Need to change the charset?
    EXEC sp_OAMethod @mime, 'GetPart', @ptMime OUT, 0
    EXEC sp_OASetProperty @ptMime, 'Charset', 'utf-8'
    EXEC sp_OAMethod @mime, 'GetPart', @htMime OUT, 1
    EXEC sp_OASetProperty @htMime, 'Charset', 'utf-8'

    --  Need to change the encoding?
    EXEC sp_OASetProperty @htMime, 'Encoding', 'base64'

    --  Now show the MIME again:

    PRINT '---- After Changes ----'
    EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0

END
GO

 

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