SQL Server
SQL Server
Test if an Email Header Matches a Pattern
See more Email Object Examples
Demonstrates the Chilkat Email.HasHeaderMatching method, which returns true when the email contains a header field named by the first argument whose value matches the wildcard pattern in the second argument. The third argument selects case-sensitive matching. This example checks whether the Subject contains the word "invoice".
Background: The value pattern supports wildcards —
* matches any run of characters — so *invoice* matches any subject containing "invoice" anywhere. This is a compact way to classify or filter messages by header content, for example routing billing mail or flagging automated notices, without manually fetching the header value and testing it yourself.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Demonstrates the HasHeaderMatching method, which returns true when the email contains a
-- header field named by the first argument whose value matches the wildcard pattern in the second argument. The third argument selects
-- case-sensitive matching.
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', 'Monthly invoice #4432'
EXEC sp_OASetProperty @email, 'From', 'billing@example.com'
-- Check whether the Subject header value matches a wildcard pattern (case-insensitive).
DECLARE @match int
EXEC sp_OAMethod @email, 'HasHeaderMatching', @match OUT, 'Subject', '*invoice*', 0
IF @match = 1
BEGIN
PRINT 'The Subject header contains ''invoice''.'
END
ELSE
BEGIN
PRINT 'The Subject header does not contain ''invoice''.'
END
EXEC @hr = sp_OADestroy @email
END
GO