SQL Server
SQL Server
Remove All Attachments from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.DropAttachments method, which removes all ordinary attachments from the in-memory message. Related items (inline images, style sheets) and attached message/rfc822 emails are not affected. This example adds two attachments, drops them, and prints the count before and after.
Background: Chilkat distinguishes three kinds of enclosed content: ordinary attachments (files meant to be saved), related items (resources that support the HTML display), and nested attached messages.
DropAttachments targets only the first category — useful, for example, when forwarding or re-sending a message body without carrying its original file attachments along.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Demonstrates the DropAttachments method, which removes all ordinary attachments from
-- the email. Related items and attached messages are not affected.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @email, 'Subject', 'Drop attachments example'
DECLARE @success int
EXEC sp_OAMethod @email, 'AddStringAttachment', @success OUT, 'a.txt', 'first attachment'
EXEC sp_OAMethod @email, 'AddStringAttachment', @success OUT, 'b.txt', 'second attachment'
EXEC sp_OAGetProperty @email, 'NumAttachments', @iTmp0 OUT
PRINT 'NumAttachments before = ' + @iTmp0
-- Remove all attachments.
EXEC sp_OAMethod @email, 'DropAttachments', NULL
EXEC sp_OAGetProperty @email, 'NumAttachments', @iTmp0 OUT
PRINT 'NumAttachments after = ' + @iTmp0
EXEC @hr = sp_OADestroy @email
END
GO