SQL Server
SQL Server
Load an Email from a Chilkat XML String
See more Email Object Examples
Demonstrates the Chilkat Email.LoadXmlString method, which loads an email from a Chilkat XML representation held in a string, typically obtained from GetXml. On success, the loaded message replaces the entire current email. This example serializes one email to XML, then reconstructs it in a second object.
Background: This is the in-memory (string) counterpart to
LoadXml, which reads from a file. Pairing GetXml with LoadXmlString lets you store an email's full state as text in a database column, cache, or message queue, then rebuild the Email object later — without touching the filesystem.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 LoadXmlString method, which loads an email from a Chilkat XML string
-- (typically obtained from GetXml). On success, the loaded message replaces the entire
-- current email.
-- Create an email and serialize it to Chilkat XML (as GetXml would produce).
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', 'Saved email'
EXEC sp_OASetProperty @source, 'From', 'alice@example.com'
EXEC sp_OASetProperty @source, 'Body', 'Hello!'
DECLARE @xmlStr nvarchar(4000)
EXEC sp_OAMethod @source, 'GetXml', @xmlStr 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, 'LoadXmlString', @success OUT, @xmlStr
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