Sample code for 30+ languages & platforms
SQL Server

Get the HTML Body into a StringBuilder

See more Email Object Examples

Demonstrates the Chilkat Email.GetHtmlBodySb method, which returns the text/html body into a StringBuilder. If the first argument is true, the related images found in the MIME are inlined as base64 data URLs directly within the returned HTML. This example retrieves the HTML body without inlining images.

Background: The inline-images option is useful for producing self-contained HTML that displays correctly in a browser or web view without needing the separate related parts — each cid: reference is replaced by a data: URL holding the image bytes. Be aware this can substantially enlarge the HTML, since base64 embedding adds roughly a third to each image's size. Writing into a StringBuilder is efficient for that potentially large output.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Demonstrates the GetHtmlBodySb method, which returns the text/html body into a
    --  StringBuilder.  If the first argument is true, related images found in the MIME are
    --  inlined as base64 data URLs directly within the returned HTML.

    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', 'GetHtmlBodySb example'

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

    --  Get the HTML body into a StringBuilder (false = do not inline related images).
    DECLARE @sbHtml int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbHtml OUT

    EXEC sp_OAMethod @email, 'GetHtmlBodySb', @success OUT, 0, @sbHtml
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @email
        EXEC @hr = sp_OADestroy @sbHtml
        RETURN
      END

    EXEC sp_OAMethod @sbHtml, 'GetAsString', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @email
    EXEC @hr = sp_OADestroy @sbHtml


END
GO