Sample code for 30+ languages & platforms
SQL Server

Create a multipart/mixed MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.NewMultipartMixed method, which initializes the object as an empty multipart/mixed entity, clearing any existing content. It takes no arguments; child parts are then appended.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: multipart/mixed is the container for independent parts shown one after another — the classic "message body plus attachments" layout. Each child is its own distinct content, unlike multipart/alternative (competing renderings of the same thing) or multipart/related (a part and its embedded resources). Start here, then AppendPart a body and AppendPartFromFile the attachments.

Chilkat SQL Server Downloads

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

    --  Demonstrates the Mime.NewMultipartMixed method, which initializes the object as an empty
    --  multipart/mixed entity, clearing any existing headers, body, and child parts.  It takes no
    --  arguments.

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

    EXEC sp_OAMethod @mime, 'NewMultipartMixed', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    --  Append child parts.  multipart/mixed is the container for a message body plus attachments.
    DECLARE @bodyPart int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @bodyPart OUT

    EXEC sp_OAMethod @bodyPart, 'SetBodyFromPlainText', @success OUT, 'See the attached report.'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @bodyPart, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        EXEC @hr = sp_OADestroy @bodyPart
        RETURN
      END
    EXEC sp_OAMethod @mime, 'AppendPart', @success OUT, @bodyPart
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        EXEC @hr = sp_OADestroy @bodyPart
        RETURN
      END

    EXEC sp_OAMethod @mime, 'AppendPartFromFile', @success OUT, 'qa_data/report.pdf'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        EXEC @hr = sp_OADestroy @bodyPart
        RETURN
      END


    EXEC sp_OAGetProperty @mime, 'NumParts', @iTmp0 OUT
    PRINT 'Number of parts: ' + @iTmp0

    EXEC @hr = sp_OADestroy @mime
    EXEC @hr = sp_OADestroy @bodyPart


END
GO