SQL Server
SQL Server
Convert an Email to Chilkat XML
See more Email Object Examples
Demonstrates the Chilkat Email.GetXml method, which converts the email object to an XML document in memory. The XML is Chilkat's own email-object representation — it is not MIME and not a standardized interchange format. This example builds a message and prints its XML.
Background: This XML form is a Chilkat-specific way to serialize an
Email object that can be reloaded with LoadXml / LoadXmlString. Because it is not standard MIME, other mail software cannot read it. In practice the standard .eml format (GetMime / SaveEml) is preferred even within Chilkat-based software: .eml 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
-- Demonstrates the GetXml method, which converts the email object to an XML document in
-- memory. The XML is Chilkat's email-object representation (not MIME and not a
-- standardized interchange format).
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', 'GetXml example'
EXEC sp_OASetProperty @email, 'From', 'alice@example.com'
DECLARE @success int
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Bob', 'bob@example.com'
EXEC sp_OASetProperty @email, 'Body', 'Hello!'
-- Convert the email to Chilkat's XML representation.
DECLARE @xmlStr nvarchar(4000)
EXEC sp_OAMethod @email, 'GetXml', @xmlStr OUT
PRINT @xmlStr
EXEC @hr = sp_OADestroy @email
END
GO