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.
<%@ Page Language="C#" EnableSessionState="false" EnableViewState="false" %> <%@ Import namespace="Hexillion.HexValidEmail.Interop" %> <script runat="server" > // SimpleEmailValidation sample in C# // version 2003-12-12 // // Demonstrates basic email address validation with // HexValidEmail COM using .NET interop. // // HexGadget components required: // HexValidEmail COM // (For more info, go to http://www.Hexillion.com/hg/ ) // // History: // 2003-12-12 Created // // Copyright 2003 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. void Page_Load() { if( IsPostBack ) { // Create an instance of the Connection class Connection hve = new Connection(); // Identify yourself for SMTP (use your own information here) // See http://www.hexillion.com/docs/guides/HexValidEmail/concepts/polite_usage.htm hve.FromDomain = "hexillion.com"; // The domain name of your machine hve.FromEmail = "HexValidEmail@hexillion.com"; // Email address of technical contact person // Set timeouts (optional) hve.Timeouts.Item(HexValidEmailTimeout.hexVeTimeoutDnsTotal).Value = 4000; hve.Timeouts.Item(HexValidEmailTimeout.hexVeTimeoutSmtpTotal).Value = 10000; // Do the validation to SMTP level HexValidEmailLevel rating = (HexValidEmailLevel)hve.Validate( email.Text, HexValidEmailLevel.hexVeLevelSmtp ); // If the address is definitely bad... if( HexValidEmailLevel.hexVeLevelBad == rating ) // Display the reason why output.Text = "Bad address: " + ((HexValidEmailErrors)hve.Error).ToString(); // If validation didn't reach intended level... else if( rating < HexValidEmailLevel.hexVeLevelSmtp ) // Say why output.Text = "No problems were found with the address, " + "but the validation failed at level " + ((int)rating + 1).ToString() + " with the following error: " + ((HexValidEmailErrors)hve.Error).ToString(); else // No problems encountered output.Text = "No problems were found with the address, though that does not guarantee it is good."; } } </script> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Simple Email Validation</title> </head> <body> <form id="MainForm" runat="server"> <p>Email address<br /> <asp:TextBox id="email" runat="server" /> <asp:Button id="submit" text="Submit" runat="server" /> </p> <asp:Label id="output" runat="server" /> </form> </body> </html>