Sample code for 30+ languages & platforms
SQL Server

Set the HTML Body of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.SetHtmlBody method, which creates or replaces the text/html body of an email. It does not automatically create a plain-text alternative. This example sets an HTML body and confirms its presence.

Background: SetHtmlBody gives you explicit control over the HTML representation, unlike the general Body property which guesses the body type from the content. For a well-formed message you would typically also add a plain-text alternative (with AddPlainTextAlternativeBody) so text-only clients, accessibility tools, and spam filters have a fallback to read.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    --  Demonstrates the SetHtmlBody method, which creates or replaces the text/html body of an
    --  email.  It does not automatically create a plain-text alternative.

    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', 'Set HTML body'

    --  Set the HTML body.
    EXEC sp_OAMethod @email, 'SetHtmlBody', NULL, '<html><body><h1>Welcome</h1><p>This is an HTML email.</p></body></html>'


    EXEC sp_OAMethod @email, 'HasHtmlBody', @iTmp0 OUT
    PRINT 'HasHtmlBody: ' + @iTmp0
    EXEC sp_OAMethod @email, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @email


END
GO