SQL Server
SQL Server
Embed a Message as message/rfc822
See more MIME Examples
Demonstrates the Chilkat Mime.NewMessageRfc822 method, which clears the object and initializes it as a message/rfc822 entity whose body is a serialized copy of another Mime. The only argument is the message to embed.
Background:
message/rfc822 wraps a whole email as the body of another — the mechanism behind forwarding a message "as attachment" or bundling one message inside another. The inner message is copied at the time of the call, so later edits to the source do not change the embedded copy. The result is a self-contained part a mail client will present as a nested message.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the Mime.NewMessageRfc822 method, which clears the current object and initializes
-- it as a message/rfc822 entity whose body is a serialized copy of another Mime. The only
-- argument is the Mime to embed.
-- Build the inner message to embed.
DECLARE @innerMsg int
EXEC @hr = sp_OACreate 'Chilkat.Mime', @innerMsg OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @innerMsg, 'SetHeaderField', @success OUT, 'Subject', 'Forwarded message'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @innerMsg, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @innerMsg
RETURN
END
EXEC sp_OAMethod @innerMsg, 'SetBodyFromPlainText', @success OUT, 'This is the original message being forwarded.'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @innerMsg, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @innerMsg
RETURN
END
-- Wrap it as message/rfc822 (an embedded/forwarded email).
DECLARE @mime int
EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
EXEC sp_OAMethod @mime, 'NewMessageRfc822', @success OUT, @innerMsg
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @innerMsg
EXEC @hr = sp_OADestroy @mime
RETURN
END
EXEC sp_OAGetProperty @mime, 'ContentType', @sTmp0 OUT
PRINT 'Content-Type: ' + @sTmp0
EXEC @hr = sp_OADestroy @innerMsg
EXEC @hr = sp_OADestroy @mime
END
GO