SQL Server
SQL Server
Remove All Related Items from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.DropRelatedItems method, which removes all related items (embedded images, style sheets, and similar resources) from the email at once. This example adds two related items and then drops them all, printing the count before and after.
Background: Related items are the inline resources bundled with an HTML body inside a
multipart/related enclosure. Dropping them all in one call is handy when you want to keep the HTML text but discard its embedded media — for instance, converting a rich message to a lightweight, text-focused version, or clearing inline images before re-adding fresh ones. To remove a single item instead, use DropRelatedItem with its index.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Demonstrates the DropRelatedItems method, which removes all related items (embedded
-- images, style sheets, etc.) from the email at once.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Set an HTML body that references two related items by name (Content-Location).
EXEC sp_OAMethod @email, 'SetHtmlBody', NULL, '<html><head><link rel="stylesheet" href="styles.css"/></head><body><img src="logo.png"/></body></html>'
-- Add two related items.
EXEC sp_OAMethod @email, 'AddRelatedString2', NULL, 'styles.css', 'body { color: navy; }', 'utf-8'
EXEC sp_OAMethod @email, 'AddRelatedString2', NULL, 'logo.png', '(pretend image data)', 'utf-8'
EXEC sp_OAGetProperty @email, 'NumRelatedItems', @iTmp0 OUT
PRINT 'NumRelatedItems before = ' + @iTmp0
-- Remove all related items.
EXEC sp_OAMethod @email, 'DropRelatedItems', NULL
EXEC sp_OAGetProperty @email, 'NumRelatedItems', @iTmp0 OUT
PRINT 'NumRelatedItems after = ' + @iTmp0
EXEC @hr = sp_OADestroy @email
END
GO