Sample code for 30+ languages & platforms
SQL Server

Check Whether an Email Has an HTML Body

See more Email Object Examples

Demonstrates the Chilkat Email.HasHtmlBody method, which returns true only when a text/html body is present in the current email object. This example sets an HTML body and confirms its presence.

Background: Because a message may contain a plain-text body, an HTML body, both, or neither, it is good practice to test before extracting. HasHtmlBody lets you decide whether to call GetHtmlBody or fall back to GetPlainTextBody — avoiding surprises when a sender provides only one representation.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    --  Demonstrates the HasHtmlBody method, which returns true only when a text/html body is
    --  present in the current 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', 'HasHtmlBody example'

    EXEC sp_OAMethod @email, 'SetHtmlBody', NULL, '<html><body><b>Hello in HTML.</b></body></html>'

    EXEC sp_OAMethod @email, 'HasHtmlBody', @iTmp0 OUT
    IF @iTmp0 = 1
      BEGIN

        PRINT 'The email has an HTML body.'
      END
    ELSE
      BEGIN

        PRINT 'The email does not have an HTML body.'
      END

    EXEC @hr = sp_OADestroy @email


END
GO