SQL Server
SQL Server
MIME Content Part Descriptor Properties
See more MIME Examples
Demonstrates the properties that describe an individual MIME content part: Charset (the charset parameter of Content-Type), Encoding (the Content-Transfer-Encoding), Disposition (the Content-Disposition value), Filename (the filename parameter of Content-Disposition), and Name (the name parameter of Content-Type). Each is set and then read back, and the effect is visible in the serialized MIME header.
Background. These properties operate on the current MIME entity's header fields. Filename and Name are receiver-facing labels, not local filesystem paths, and Charset is meaningful for text parts.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
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, 'SetBodyFromPlainText', @success OUT, 'The quick brown fox.'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
RETURN
END
-- Charset is the charset parameter of the Content-Type header field (meaningful for text parts).
EXEC sp_OASetProperty @mime, 'Charset', 'utf-8'
-- Encoding is the Content-Transfer-Encoding for this part.
EXEC sp_OASetProperty @mime, 'Encoding', 'quoted-printable'
-- Disposition, Filename, and Name describe how a receiver should present the part.
-- Filename is the filename parameter of Content-Disposition; Name is the name parameter of
-- Content-Type. Both are receiver-facing names, not local filesystem paths.
EXEC sp_OASetProperty @mime, 'Disposition', 'attachment'
EXEC sp_OASetProperty @mime, 'Filename', 'note.txt'
EXEC sp_OASetProperty @mime, 'Name', 'note.txt'
-- Read the descriptors back.
EXEC sp_OAGetProperty @mime, 'Charset', @sTmp0 OUT
PRINT 'Charset = ' + @sTmp0
EXEC sp_OAGetProperty @mime, 'Encoding', @sTmp0 OUT
PRINT 'Encoding = ' + @sTmp0
EXEC sp_OAGetProperty @mime, 'Disposition', @sTmp0 OUT
PRINT 'Disposition = ' + @sTmp0
EXEC sp_OAGetProperty @mime, 'Filename', @sTmp0 OUT
PRINT 'Filename = ' + @sTmp0
EXEC sp_OAGetProperty @mime, 'Name', @sTmp0 OUT
PRINT 'Name = ' + @sTmp0
-- The descriptors appear in the serialized MIME header.
DECLARE @mimeStr nvarchar(4000)
EXEC sp_OAMethod @mime, 'GetMime', @mimeStr OUT
EXEC sp_OAGetProperty @mime, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mime
RETURN
END
PRINT @mimeStr
EXEC @hr = sp_OADestroy @mime
END
GO