SQL Server
SQL Server
Get the Plain-Text Body of an Email
See more Email Object Examples
Demonstrates the Chilkat Email.GetPlainTextBody method, which returns the email body having the text/plain content type. It reads the plain-text representation already present in the email object rather than generating one from HTML. This example sets a plain-text body and reads it back.
Background: The plain-text body is the fallback representation of a message — the version shown when HTML can't or shouldn't be rendered, and the form usually preferred for search, indexing, and accessibility.
GetPlainTextBody targets it specifically; if the message contains only HTML, this returns empty (check with HasPlainTextBody), so a robust extractor falls back to GetHtmlBody when needed.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 GetPlainTextBody method, which returns the email body having the
-- text/plain content type. It reads the plain-text representation already present in the
-- email object.
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', 'GetPlainTextBody example'
EXEC sp_OAMethod @email, 'SetTextBody', NULL, 'Hello, this is the plain-text body.', 'text/plain'
-- Retrieve the text/plain body.
DECLARE @plain nvarchar(4000)
EXEC sp_OAMethod @email, 'GetPlainTextBody', @plain OUT
PRINT @plain
EXEC @hr = sp_OADestroy @email
END
GO