Sample code for 30+ languages & platforms
SQL Server

Check Whether an Email Has a Plain-Text Body

See more Email Object Examples

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

Background: The plain-text body is the fallback representation used when HTML is unavailable or unwanted — and the form usually preferred for search, indexing, and accessibility. HasPlainTextBody is the counterpart to HasHtmlBody; testing both lets a program handle every combination (text-only, HTML-only, both, or neither) gracefully.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    --  Demonstrates the HasPlainTextBody method, which returns true only when a text/plain 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', 'HasPlainTextBody example'

    EXEC sp_OAMethod @email, 'SetTextBody', NULL, 'Hello, this is the plain-text body.', 'text/plain'

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

        PRINT 'The email has a plain-text body.'
      END
    ELSE
      BEGIN

        PRINT 'The email does not have a plain-text body.'
      END

    EXEC @hr = sp_OADestroy @email


END
GO