SQL Server
SQL Server
Load an Email from a Chilkat XML String
See more Email Object Examples
Demonstrates the Chilkat Email.SetFromXmlText method, which loads an email from a Chilkat XML string (as produced by GetXml). On success, it replaces the entire current email. This example serializes one email to XML, then reconstructs it in a second object.
Background: This loads Chilkat's XML email representation from a string — the in-memory counterpart to
LoadXml. The XML format is an alternative to standard MIME, but for most purposes the MIME form (SetFromMimeText / GetMime) is preferred: it is interoperable and also preserves Chilkat's CKX- metadata headers (which are always removed before an email is sent), so the XML format offers no metadata advantage.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the SetFromXmlText method, which loads an email from a Chilkat XML string.
-- On success, it replaces the entire current email.
-- Build a source email and serialize it to Chilkat XML.
DECLARE @source int
EXEC @hr = sp_OACreate 'Chilkat.Email', @source OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @source, 'Subject', 'Source message'
EXEC sp_OASetProperty @source, 'From', 'alice@example.com'
EXEC sp_OASetProperty @source, 'Body', 'Hello!'
DECLARE @xmlText nvarchar(4000)
EXEC sp_OAMethod @source, 'GetXml', @xmlText OUT
-- Load a new email object from the XML string.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
EXEC sp_OAMethod @email, 'SetFromXmlText', @success OUT, @xmlText
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @source
EXEC @hr = sp_OADestroy @email
RETURN
END
EXEC sp_OAGetProperty @email, 'Subject', @sTmp0 OUT
PRINT 'Loaded subject: ' + @sTmp0
EXEC @hr = sp_OADestroy @source
EXEC @hr = sp_OADestroy @email
END
GO