SQL Server Requires Chilkat v11.0.0+
SQL Server
Read the plain-text and HTML bodies separately
See more Email Object Examples
When both alternatives exist, Body returns HTML. Use the explicit body accessors to choose text for an index or HTML for a viewer. This example reads alternatives.eml from the previous example.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @iTmp1 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
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_OAMethod @email, 'LoadEml', @success OUT, 'alternatives.eml'
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
RETURN
END
-- A message can have either representation, both, or neither.
EXEC sp_OAMethod @email, 'HasPlainTextBody', @iTmp0 OUT
IF @iTmp0 = 1
BEGIN
EXEC sp_OAMethod @email, 'GetPlainTextBody', @sTmp0 OUT
PRINT 'Plain text: ' + @sTmp0
END
EXEC sp_OAMethod @email, 'HasHtmlBody', @iTmp0 OUT
IF @iTmp0 = 1
BEGIN
EXEC sp_OAMethod @email, 'GetHtmlBody', @sTmp0 OUT
PRINT 'HTML source: ' + @sTmp0
END
EXEC sp_OAMethod @email, 'HasPlainTextBody', @iTmp0 OUT
EXEC sp_OAMethod @email, 'HasHtmlBody', @iTmp1 OUT
IF (@iTmp0 = 0) and (@iTmp1 = 0)
BEGIN
PRINT 'No text or HTML body. Inspect the MIME parts.'
END
EXEC @hr = sp_OADestroy @email
END
GO