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
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

Convert Email HTML to Plain-Text Alternative

Loads an HTML email from a web page, converts the HTML to a plain-text alternative body, and sends it.

Download Chilkat Email ActiveX

Download Chilkat HTML-to-XML ActiveX (also includes HTML-to-PlainText conversion)

Download Chilkat MHT 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

    --  The MHT component can be used to convert an HTML page
    --  from a URL, file, or in-memory HTML into an email
    --  with embedded images and style sheets.
    DECLARE @mht int
    EXEC @hr = sp_OACreate 'Chilkat.Mht', @mht 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 'MailMan component unlock failed'
        RETURN
      END

    EXEC sp_OAMethod @mht, 'UnlockComponent', @success OUT, '30-day trial'
    IF @success <> 1
      BEGIN
        PRINT 'Mht component unlock failed'
        RETURN
      END

    DECLARE @email int

    EXEC sp_OASetProperty @mht, 'UseCids', 1
    EXEC sp_OAMethod @mht, 'GetEmail', @email OUT, 'http://www.bonairefishing.com/'
    IF @email Is NULL 
      BEGIN
        EXEC sp_OAGetProperty @mht, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    EXEC sp_OASetProperty @email, 'Subject', 'Test HTML/plain-text email'

    EXEC sp_OAMethod @email, 'AddTo', NULL, 'Chilkat Support', 'support@chilkatsoft.com'
    EXEC sp_OASetProperty @email, 'From', 'admin@chilkatsoft.com'

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

    EXEC sp_OAMethod @h2t, 'UnlockComponent', @success OUT, 'Anything for 30-day trial'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @h2t, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END
    --  Get the email's HTML body.
    DECLARE @html nvarchar(4000)

    EXEC sp_OAMethod @email, 'GetHtmlBody', @html OUT

    --  Convert it to plain text:
    DECLARE @plainText nvarchar(4000)

    EXEC sp_OAMethod @h2t, 'ToText', @plainText OUT, @html

    --  Add a plain-text alternative to the email:
    EXEC sp_OAMethod @email, 'AddPlainTextAlternativeBody', NULL, @plainText

    EXEC sp_OASetProperty @mailman, 'SmtpHost', 'mail.chilkatsoft.com'
    EXEC sp_OASetProperty @mailman, 'SmtpUsername', 'admin@chilkatsoft.com'
    EXEC sp_OASetProperty @mailman, 'SmtpPassword', '*myPassword5*'

    EXEC sp_OAMethod @mailman, 'SendEmail', @success OUT, @email
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    PRINT 'HTML/plain-text Email Sent!'


END
GO

 

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

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