SQL Server
SQL Server
Clear the To Recipients of an Email
See more Email Object Examples
Demonstrates the Chilkat Email.ClearTo method, which clears the list of direct (To) recipients. It changes only the current in-memory email object and does not affect messages already sent. This example adds two To recipients, clears them, and prints the count before and after.
Background: The
To list holds a message's primary recipients. When reusing one Email object as a template across multiple sends, ClearTo wipes just that list so each send addresses the right people, without disturbing the subject, body, or attachments. It pairs with ClearCC and ClearBcc for full control over the recipient lists.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Demonstrates the ClearTo method, which clears the list of direct (To) recipients.
-- This changes only the current email object.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Joe', 'joe@example.com'
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Jane', 'jane@example.com'
EXEC sp_OAGetProperty @email, 'NumTo', @iTmp0 OUT
PRINT 'NumTo before clear = ' + @iTmp0
-- Remove all To recipients.
EXEC sp_OAMethod @email, 'ClearTo', NULL
EXEC sp_OAGetProperty @email, 'NumTo', @iTmp0 OUT
PRINT 'NumTo after clear = ' + @iTmp0
EXEC @hr = sp_OADestroy @email
END
GO