Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Convert Email HTML to Plain-Text AlternativeLoads an HTML email from a web page, converts the HTML to a plain-text alternative body, and sends it.
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.