Sample code for 30+ languages & platforms
SQL Server

Append Text to an Email Body

See more Email Object Examples

Demonstrates the Chilkat Email.AppendToBody method, which appends additional text to the email's existing plain-text body rather than replacing it. This example sets an initial body and then appends more text.

Background: Setting the body (via Body or SetTextBody) replaces whatever was there, while AppendToBody adds to it. That is convenient when a message body is assembled in pieces — for example a greeting, then dynamically generated lines, then a signature — without having to concatenate the whole string yourself before assigning it.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    --  Demonstrates the AppendToBody method, which appends additional text to the email's
    --  existing plain-text body.

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

    --  Set an initial body.
    EXEC sp_OAMethod @email, 'SetTextBody', NULL, 'First line.', 'text/plain'

    --  Append more text to the existing body.
    EXEC sp_OAMethod @email, 'AppendToBody', NULL, ' Appended text.'


    EXEC sp_OAGetProperty @email, 'Body', @sTmp0 OUT
    PRINT 'Body = ' + @sTmp0

    EXEC @hr = sp_OADestroy @email


END
GO