Sample code for 30+ languages & platforms
SQL Server

Example: MailMan.RenderToMime method

Demonstrates the RenderToMime method.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Create a simple email
    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', 'This is a test'
    EXEC sp_OASetProperty @email, 'Body', 'This is a test'

    EXEC sp_OASetProperty @email, 'From', 'Joe <joe@example.com>'
    DECLARE @success int
    EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Mary', 'mary@example2.com'

    DECLARE @mailman int
    EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mailman OUT

    -- See the exact MIME of the email that would be sent
    -- if your application called SendEmail and passed in the email object.
    DECLARE @renderedMime nvarchar(4000)
    EXEC sp_OAMethod @mailman, 'RenderToMime', @renderedMime OUT, @email


    PRINT @renderedMime

    -- For this example, the rendered MIME looks like this:

    -- MIME-Version: 1.0
    -- Date: Fri, 27 Feb 2026 06:55:44 -0600
    -- Message-ID: <E4369AE94DE6CD7D08D4F15D95937F2A7FFC95E8@CHILKAT25>
    -- Content-Type: text/plain; charset=us-ascii; format=flowed
    -- Content-Transfer-Encoding: 7bit
    -- X-Priority: 3 (Normal)
    -- Subject: This is a test
    -- From: Joe <joe@example.com>
    -- To: Mary <mary@example2.com>
    -- 
    -- This is a test

    EXEC @hr = sp_OADestroy @email
    EXEC @hr = sp_OADestroy @mailman


END
GO