Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Email with XML Alternative BodyDemonstrates 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.
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.