<%@ Page Language="VB" AutoEventWireup="true" CodeFile="subscribe.aspx.vb" Inherits="subscribe" %> <HTML> <HEAD> <title>WebForm1</title> </HEAD> <body > <form id="Form1" method="post" runat="server"> Please enter your email address to subscribe to our newsletter. <br> <asp:TextBox ID="txtEmailAddress" runat=server></asp:TextBox><input type="submit" value="Submit" /> <asp:Literal ID="litMsg" Runat="server"></asp:Literal> </form> </body> </HTML>
Imports aspNetMX Partial Class subscribe Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Page.IsPostBack Then 'check email address 'download a license key from http://www.advancedintellect.com/download.aspx MXValidate.LoadLicenseKey("QET7A-A2HD3-7HAUG-M7FL2-KGFS1-AQ6A9-FWEDD-XQ21C-ZA5RC-RU7XS-XK6JY-6JT53-29XW") 'get an instance of MXValidate from the HttpCache Dim mx As New MXValidate() 'check to see if the email address is valid Dim email As String = txtEmailAddress.Text Try Dim level As MXValidateLevel = mx.Validate(email, MXValidateLevel.MXRecords) If level = MXValidateLevel.MXRecords Then 'save to the database SaveEmailAddress(email) 'write out a friendly message litMsg.Text = "Thank you for subscribing" Else litMsg.Text = "Please enter a valid email address." End If Catch 'probably dns server not available, record the email address anyway, and double check when dns 'server is back up SaveEmailAddress(email) litMsg.Text = "Thank you for subscribing" End Try End If End Sub Private Sub SaveEmailAddress(ByVal EmailAddress As String) 'this function is a placeholder and is would be used to save EmailAddress 'to your data store. End Sub End Class