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

Email with XML Alternative Body

Demonstrates how to create an email with three alternative bodies -- plain-text, HTML, and XML. It is not common to need an XML body, therefore, the Chilkat MIME component is needed to help create the email. Implementing this solution would require licenses to both Chilkat MIME and Chilkat Email (or the Chilkat Bundle, which includes all Chilkat components at a reduced price).

Important: The MIME object is only needed for the 3rd alternative body having the type text/xml. Creating emails with two alternative bodies (HTML and plain-text) is possible using only the Chilkat Email component.

Download Chilkat Email ActiveX

Download 32-bit Chilkat IMAP ActiveX (.msi)

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

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

Download Chilkat MIME ActiveX

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
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    EXEC sp_OAMethod @mime, 'NewMultipartAlternative', NULL

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

    EXEC sp_OAMethod @mimeHtml, 'SetBodyFromHtml', NULL, '<html><body>HTML Body</body></html>'

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

    EXEC sp_OAMethod @mimeText, 'SetBodyFromPlainText', NULL, 'Plain text body'

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

    EXEC sp_OAMethod @mimeXml, 'SetBodyFromXml', NULL, '<test>XML Body</test>'

    EXEC sp_OAMethod @mime, 'AppendPart', NULL, @mimeHtml
    EXEC sp_OAMethod @mime, 'AppendPart', NULL, @mimeText
    EXEC sp_OAMethod @mime, 'AppendPart', NULL, @mimeXml

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

    EXEC sp_OAMethod @email, 'SetFromMimeObject', NULL, @mime

    EXEC sp_OASetProperty @email, 'Subject', 'This is a test'
    EXEC sp_OASetProperty @email, 'From', 'support@chilkatsoft.com'
    EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Chilkat Sales', 'sales@chilkatsoft.com'
    --  ...
    --  You may send the email using the Chilkat MailMan object...
    --  ...

    EXEC sp_OAMethod @email, 'SaveEml', @success OUT, 'email.eml'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END
END
GO

 

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