SQL Server
SQL Server
Convert a MIME Entity to multipart/alternative
See more MIME Examples
Demonstrates the Chilkat Mime.ConvertToMultipartAlt method, which wraps the current entity in a new outer multipart/alternative, making the original the first child. It takes no arguments.
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: Use this to add an alternate rendering to an existing message — for example, promoting a plain-text message so an HTML version can be added alongside it. The original content becomes the first (least-preferred) alternative, and you append the richer representation after it. As with the mixed conversion, message-level headers move to the new outer entity.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
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, 'LoadMimeFile', @success OUT, 'qa_data/message.eml'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
RETURN
END
-- Wrap the current entity in a new outer multipart/alternative entity. The original entity
-- becomes the first child, ready for an alternate representation to be added.
EXEC sp_OAMethod @mime, 'ConvertToMultipartAlt', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
RETURN
END
-- Add an alternative representation of the same content.
DECLARE @htmlPart int
EXEC @hr = sp_OACreate 'Chilkat.Mime', @htmlPart OUT
EXEC sp_OAMethod @htmlPart, 'SetBodyFromHtml', @success OUT, '<html><body>HTML alternative.</body></html>'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @htmlPart, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
EXEC @hr = sp_OADestroy @htmlPart
RETURN
END
EXEC sp_OAMethod @mime, 'AppendPart', @success OUT, @htmlPart
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
EXEC @hr = sp_OADestroy @htmlPart
RETURN
END
EXEC sp_OAGetProperty @mime, 'NumParts', @iTmp0 OUT
PRINT 'Number of parts: ' + @iTmp0
EXEC @hr = sp_OADestroy @mime
EXEC @hr = sp_OADestroy @htmlPart
END
GO