Note: This is not the complete source code--just the main source file.
You can download the full source (with include files) from our sample code archive by clicking on the diskette icons.
SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO -- SimpleEmailValidation sample in Transact-SQL -- version 2004-03-11 -- -- Demonstrates basic email address validation with -- HexValidEmail COM in a T-SQL stored procedure -- -- HexGadget components required: -- HexValidEmail COM -- (For more info, go to http://www.Hexillion.com/hg/ ) -- -- History: -- 2004-03-11 Created -- -- Copyright 2004 Hexillion Technologies. All rights reserved. -- -- THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY -- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT -- LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND/OR -- FITNESS FOR A PARTICULAR PURPOSE. CREATE PROCEDURE sp_SimpleEmailValidation @emailAddress varchar( 255 ), @validationLevel int, @rating int out, @error int out AS DECLARE @hr int DECLARE @hve int DECLARE @timeoutCollection int DECLARE @dnsTimeout int DECLARE @smtpTimeout int -- Set default values for return vars SELECT @rating = 0 SELECT @error = -1 -- Create a Connection object EXEC @hr = sp_OACreate 'HexValidEmail.Connection', @hve out IF @hr <> 0 RETURN @hr -- Identify yourself for SMTP (use your own information here) -- See http://www.hexillion.com/docs/guides/HexValidEmail/concepts/polite_usage.htm EXEC @hr = sp_OASetProperty @hve, 'FromDomain', 'hexillion.com' -- The domain name of your machine IF @hr <> 0 RETURN @hr EXEC @hr = sp_OASetProperty @hve, 'FromEmail', 'HexValidEmail@hexillion.com' -- Email address of technical contact person IF @hr <> 0 RETURN @hr -- Set timeouts (optional) EXEC @hr = sp_OAGetProperty @hve, 'Timeouts', @timeoutCollection out IF @hr <> 0 RETURN @hr EXEC @hr = sp_OAMethod @timeoutCollection, 'Item', @dnsTimeout out, 1 IF @hr <> 0 RETURN @hr EXEC @hr = sp_OASetProperty @dnsTimeout, 'Value', 4000 IF @hr <> 0 RETURN @hr EXEC @hr = sp_OAMethod @timeoutCollection, 'Item', @smtpTimeout out, 2 IF @hr <> 0 RETURN @hr EXEC @hr = sp_OASetProperty @smtpTimeout, 'Value', 10000 IF @hr <> 0 RETURN @hr -- Do the validation EXEC @hr = sp_OAMethod @hve, 'Validate', @rating out, @emailAddress, @validationLevel IF @hr <> 0 RETURN @hr -- Get the error code EXEC @hr = sp_OAGetProperty @hve, 'Error', @error out -- Interpreting the results IF @rating = 0 PRINT 'Bad address: ' + CAST( @error as varchar ) ELSE IF @rating < @validationLevel PRINT 'No problems were found with the address, but the validation failed at level ' + CAST( (@rating + 1) as varchar ) + ' with the following error: ' + CAST( @error as varchar ) ELSE PRINT 'No problems were found with the address, though that does not guarantee it is good.' RETURN @hr GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO