SQL Server
SQL Server
Remove All Attached Messages from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveAttachedMessages method, which removes all message/rfc822 sub-parts (attached emails) from the object at once. Ordinary file attachments and related HTML resources are left unchanged. This example attaches two emails, removes them all, and prints the count before and after.
Background: This is the "remove them all" companion to
RemoveAttachedMessage. Because it touches only the nested-message parts, you can strip forwarded originals or a digest's members while preserving the message body, its inline images, and any regular attachments — a clean way to keep the carrier message while discarding what it enclosed.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Demonstrates the RemoveAttachedMessages method, which removes all message/rfc822
-- sub-parts (attached emails) from the email at once. Ordinary file attachments and
-- related items are not affected.
DECLARE @inner1 int
EXEC @hr = sp_OACreate 'Chilkat.Email', @inner1 OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @inner1, 'Subject', 'Embedded 1'
DECLARE @inner2 int
EXEC @hr = sp_OACreate 'Chilkat.Email', @inner2 OUT
EXEC sp_OASetProperty @inner2, 'Subject', 'Embedded 2'
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
EXEC sp_OASetProperty @email, 'Subject', 'Has attached messages'
DECLARE @success int
EXEC sp_OAMethod @email, 'AttachEmail', @success OUT, @inner1
EXEC sp_OAMethod @email, 'AttachEmail', @success OUT, @inner2
EXEC sp_OAGetProperty @email, 'NumAttachedMessages', @iTmp0 OUT
PRINT 'NumAttachedMessages before = ' + @iTmp0
-- Remove all attached messages.
EXEC sp_OAMethod @email, 'RemoveAttachedMessages', NULL
EXEC sp_OAGetProperty @email, 'NumAttachedMessages', @iTmp0 OUT
PRINT 'NumAttachedMessages after = ' + @iTmp0
EXEC @hr = sp_OADestroy @inner1
EXEC @hr = sp_OADestroy @inner2
EXEC @hr = sp_OADestroy @email
END
GO