Sample code for 30+ languages & platforms
SQL Server

Add Content-Length Header to a MIME Message

See more MIME Examples

The AddContentLength method automatically computes the length of the MIME content and adds a Content-Length header with the correct number of bytes.

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
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @mime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Set the MIME body:
    EXEC sp_OAMethod @mime, 'SetBody', NULL, 'This is a test'

    -- The complete size (in bytes) of the contents is computed, 
    -- even if the MIME is multipart, and the Content-Length header
    -- is added.
    EXEC sp_OAMethod @mime, 'AddContentLength', NULL

    -- Display the MIME:
    EXEC sp_OAMethod @mime, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @mime


END
GO