SQL Server
SQL Server
Get the Value of the Nth Header Field
See more Email Object Examples
Demonstrates the Chilkat Email.GetHeaderFieldValue method, which returns the value of the Nth header field. Indexing begins at 0, and the count comes from NumHeaderFields. This example walks every header field, printing each name together with its value.
Background:
GetHeaderFieldValue is the value half of index-based header enumeration — GetHeaderFieldName gives the field name at the same index. Iterating both is the reliable way to dump or inspect a full header block, including any repeated fields, which a name-based lookup would collapse to a single occurrence.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @sTmp1 nvarchar(4000)
-- Demonstrates the GetHeaderFieldValue method, which returns the value of the Nth header
-- field. Indexing begins at 0; the number of header fields is given by NumHeaderFields.
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', 'Enumerate header values'
EXEC sp_OASetProperty @email, 'From', 'alice@example.com'
DECLARE @success int
EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Bob', 'bob@example.com'
DECLARE @n int
EXEC sp_OAGetProperty @email, 'NumHeaderFields', @n OUT
DECLARE @i int
SELECT @i = 0
WHILE @i <= @n - 1
BEGIN
EXEC sp_OAMethod @email, 'GetHeaderFieldName', @sTmp0 OUT, @i
EXEC sp_OAMethod @email, 'GetHeaderFieldValue', @sTmp1 OUT, @i
PRINT @sTmp0 + ' = ' + @sTmp1
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @email
END
GO