SQL Server
SQL Server
Remove the HTML Body from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveHtmlAlternative method, which removes the HTML body from the email if one exists. Other body representations, attachments, and related items remain unchanged. This example builds a message with both plain-text and HTML alternatives, then removes the HTML.
Background: A
multipart/alternative message carries the same content as both HTML and plain text. Dropping the HTML alternative yields a leaner, text-only message — useful for reducing size, sidestepping HTML-rendering or spam concerns, or enforcing a plain-text policy. The plain-text alternative remains as the message body. Its counterpart is RemovePlainTextAlternative.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Demonstrates the RemoveHtmlAlternative method, which removes the HTML body from the email
-- (if one exists). Other body representations, attachments, and related items remain.
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', 'Remove HTML alternative'
-- Create an email with both plain-text and HTML alternatives.
EXEC sp_OAMethod @email, 'SetTextBody', NULL, 'This is the plain-text version.', 'text/plain'
DECLARE @success int
EXEC sp_OAMethod @email, 'AddHtmlAlternativeBody', @success OUT, '<html><body>This is the HTML version.</body></html>'
EXEC sp_OAGetProperty @email, 'NumAlternatives', @iTmp0 OUT
PRINT 'NumAlternatives before = ' + @iTmp0
EXEC sp_OAMethod @email, 'HasHtmlBody', @iTmp0 OUT
PRINT 'HasHtmlBody before: ' + @iTmp0
-- Remove the HTML body, leaving the plain-text alternative.
EXEC sp_OAMethod @email, 'RemoveHtmlAlternative', NULL
EXEC sp_OAGetProperty @email, 'NumAlternatives', @iTmp0 OUT
PRINT 'NumAlternatives after = ' + @iTmp0
EXEC sp_OAMethod @email, 'HasHtmlBody', @iTmp0 OUT
PRINT 'HasHtmlBody after: ' + @iTmp0
EXEC @hr = sp_OADestroy @email
END
GO