subscribe.aspx HTML Source

 

<%@ Page language="c#" Codefile="subscribe.aspx.cs" AutoEventWireup="true" 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>

 

 

subscribe.aspx.cs Source

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using aspNetMX;

public partial class subscribe : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Page.IsPostBack) //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
            MXValidate mx = new MXValidate();

            //check to see if the email address is valid
            string email = txtEmailAddress.Text;
            try
            {
                MXValidateLevel level = mx.Validate(email, MXValidateLevel.MXRecords);
                if (level == MXValidateLevel.MXRecords)
                {
                    //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.";
                }

            }
            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";

            }
        }

    }

    private void SaveEmailAddress(string EmailAddress)
    {
        //this function is a placeholder and is would be used to save EmailAddress
        //to your data store.
    }

}