SQL Server
SQL Server
Save an Email to a Chilkat XML File
See more Email Object Examples
Demonstrates the Chilkat Email.SaveXml method, which converts the email object to Chilkat's XML representation and saves it to a file. It can later be reloaded with LoadXml. This example builds a message and saves it as XML.
Background: This XML format is an alternative to the standard
.eml (MIME) format for persisting an email. Note that .eml also preserves Chilkat's CKX- metadata headers (which are always removed before an email is sent), so it captures the same information. Because .eml is universal and interoperable, Chilkat recommends using SaveEml / LoadEml over the XML format — even within Chilkat-based software.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the SaveXml method, which converts the email object to Chilkat's XML
-- representation and saves it to a file. It can later be reloaded with LoadXml.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @email, 'Subject', 'Save as XML'
EXEC sp_OASetProperty @email, 'From', 'alice@example.com'
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Bob', 'bob@example.com'
EXEC sp_OASetProperty @email, 'Body', 'Hello!'
-- Save the email to a Chilkat XML file.
EXEC sp_OAMethod @email, 'SaveXml', @success OUT, 'qa_output/email.xml'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
RETURN
END
PRINT 'Saved to email.xml.'
-- Note: The path "qa_output/..." is a relative local filesystem path,
-- relative to the current working directory of the running application.
EXEC @hr = sp_OADestroy @email
END
GO