Sample code for 30+ languages & platforms
SQL Server

Create an Inline-Forward Email

See more Email Object Examples

Demonstrates the Chilkat Email.ToForward method, which creates an inline-forward email based on this email. The forward is returned in the argument, and the source email is not modified. The returned email can be edited — adding recipients, prepending a note — before sending. This example forwards a message and adds a recipient.

Background: An inline forward quotes the original message's content within the body of the new message — the familiar "---------- Forwarded message ----------" style — as opposed to attaching the original as a message/rfc822 part (which AttachEmail does). Chilkat assembles the quoted body and headers for you, leaving the new message ready to address and send.

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 ToForward method, which creates an inline-forward email based on this
    --  email.  The forward is returned in the argument; the source email is not modified.

    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', 'Quarterly results'
    EXEC sp_OASetProperty @email, 'From', 'alice@example.com'
    EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Bob', 'bob@example.com'
    EXEC sp_OASetProperty @email, 'Body', 'Here are the quarterly results.'

    --  Create an inline-forward email from this message.
    DECLARE @fwd int
    EXEC @hr = sp_OACreate 'Chilkat.Email', @fwd OUT

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

    --  The forward can be edited to add recipients before sending.
    EXEC sp_OAMethod @fwd, 'AddTo', @success OUT, 'Carol', 'carol@example.com'

    EXEC sp_OAMethod @fwd, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @email
    EXEC @hr = sp_OADestroy @fwd


END
GO