SQL Server
SQL Server
Add Duplicate Header Fields to an Email
See more Email Object Examples
Demonstrates the Chilkat Email.AddHeaderField2 method. It works like AddHeaderField, except that if the header field already exists it is not replaced — a duplicate header is added instead. Use it for headers that may legally occur more than once, such as Received. This example adds two headers with the same name and prints the header showing both.
Background: The email standards allow certain header fields to repeat. The classic case is
Received: each mail server that handles a message prepends its own Received line, so a delivered email typically has several, forming a trace of the path it took. Single-valued fields like Subject should be replaced (use AddHeaderField), whereas repeatable fields need AddHeaderField2 so earlier occurrences are preserved rather than overwritten.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
-- Demonstrates the AddHeaderField2 method. It is the same as AddHeaderField, except that
-- if the header field already exists, it is NOT replaced -- a duplicate header is added.
-- Use this for headers that may legally occur more than once, such as "Received".
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', 'Duplicate header example'
EXEC sp_OASetProperty @email, 'From', 'alice@example.com'
-- Add two header fields with the same name; both are retained.
EXEC sp_OAMethod @email, 'AddHeaderField2', NULL, 'X-Trace', 'hop-1'
EXEC sp_OAMethod @email, 'AddHeaderField2', NULL, 'X-Trace', 'hop-2'
-- Both X-Trace fields are present in the header.
EXEC sp_OAGetProperty @email, 'Header', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
END
GO