Sample code for 30+ languages & platforms
SQL Server

Unobfuscate a Spammy Email

See more Email Object Examples

Demonstrates the Chilkat Email.UnSpamify method, which unobfuscates an email by undoing common spammer tricks — it removes comments from HTML bodies and unobfuscates hyperlinked URLs. This example cleans an HTML body whose link was broken up by an inserted comment.

Background: Spammers deliberately scramble HTML to slip past filters — inserting empty comments in the middle of words or URLs (exa<!--x-->mple.com), or otherwise obfuscating links — so the message renders normally to a human but confuses naive keyword matching. UnSpamify reverses those tricks, producing a normalized body that is easier to analyze, classify, or scan for the real destination of its links.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    --  Demonstrates the UnSpamify method, which unobfuscates an email by undoing common spammer
    --  tricks: it removes comments from HTML bodies and unobfuscates hyperlinked URLs.

    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', 'UnSpamify example'

    --  An HTML body with an obfuscating comment inserted into a hyperlink.
    EXEC sp_OAMethod @email, 'SetHtmlBody', NULL, '<html><body>Visit <a href="http://exa<!--x-->mple.com">our site</a>.</body></html>'

    --  Undo the obfuscation.
    EXEC sp_OAMethod @email, 'UnSpamify', NULL

    DECLARE @cleaned nvarchar(4000)
    EXEC sp_OAMethod @email, 'GetHtmlBody', @cleaned OUT

    PRINT @cleaned

    EXEC @hr = sp_OADestroy @email


END
GO