Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Newsletter
Enter your email address to receive full length articles at Stardeveloper:


Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (11)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article
Stardeveloper RSS Feed
Hosted by Securewebs.com
 
Home : .NET : ASP : Create your own Newsletter in ASP 3.0
 
RSS - Read full length articles at Stardeveloper using Stardeveloper RSS Feed RSS

Create your own Newsletter in ASP 3.0

by Faisal Khan. Follow Faisal Khan on Twitter Follow Faisal Khan on Facebook

Newsletters are part and parcel of a website nowadays. When a website visitor enters his email address in the newsletter input box, it is saved in the database. As more and more visitors subscribe, the mailing list grows. You can then send all the subscribers of your newsletter, email, whenever you like. Newsletters are an effective way to keep your website users informed of latest news and information related to your website or topic.

In this tutorial, I will guide you through the steps of creating a simple news letter using classic ASP.

If you are looking for a production ready, stable, easy to use ASP.NET Newsletter application, then look no further: Faisal Khan (the author of this tutorial) has created a great Newsletter Application for you to download and start using today. It is easy to install, lets your users subscribe using a subscription form, provides a simple administration interface to create and send newsletters, handles the task of sending newsletters in the background using thread queues on the server, and lets users unsubscribe if they wish so.

We will divide our work into three steps :

  • Step 1 : Create a simple HTML Form where users can insert their email addresses and an ASP page which will receive the Form email address from the HTML page and insert it into the database.
  • Step 2 : Create a simple Access database to store user's email addresses.
  • Step 3 : A simple admin ASP page from where you can send email messages to all the users whose email addresses are present in the database.
  • Step 4 : An ASP page from where the users can delete their email addresses from the database if they later choose to.

Alright then lets now move to the creation of our News Letter messaging system.

Simple HTML Form
Create a new HTML page and name it 'mail.htm' and then add the following code in the 'body' section of that page :-

News Letter :
<form action="mail_ac.asp" method="post">
<input type="text" name="email" size="11">
<input type="submit" value="submit">
</form>

Above HTML code will produce a simple input box where users can enter their email addresses. After entering their email address and pressing the 'submit' button, the users email address will be ported to our 'mail_ac.asp' page where the email address will be inserted into the database. You can edit it to suite the design of your site.

Form Action Page
Open notepad or any text editor for that matter and add the following lines of code into it and then save it as 'mail_ac.asp' in the same directory where you have put the above 'mail.htm' page.

	<%
' Declaring variables
Dim email, con, data_source, sql_insert, sql_check, rs
email = Request.Form("email")
' Check that email address is empty or not. If email address 
' is not empty then continue, otherwise redirect the user back to
' the main page
If Len(email) Then
' Note you can add your database's DSN here if you want
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
	
	Server.MapPath("mail.mdb")
' Our SQL statements
sql_check = "select email from users where email = '" & email & "'"
sql_insert = "insert into users( email ) values ('" & email & "')"
' Lets first check to see if the email address is alread present in
' the database. Create the instance of Connection Object and then
' open the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
Set rs = con.Execute (sql_check, , 1)
' If email address is not present then add it to the database
If rs.EOF Then
con.Execute sql_insert
' Displaying the result of successful entry to the user
Response.Write "Thank you. Your email address <b>" & email & _
"</b> was successfully entered into the database"
' But if email address is already present then display it to 
' the user
Else
Response.Write "Your email address " & email & _
" is already present in the database. Thank you."
End If
' Done. Disconnecting and setting Connection Object to Nothing
con.Close
Set con = Nothing
' And if the email address submitted was empty Then
Else
Response.Redirect "mail.htm"
End If
	%>

This 'mail_ac.asp' page will first check to see if the user has just pressed the 'submit' button and has not entered the email address, if it is so then the user will be redirected back to the 'mail.htm' page. If the user entered it's email address then first check database to see if it's already present or not. If email address is not found in the database then add it otherwise tell the user that the email address is already present and exit.

Simple Access Database
Now we will create a simple Access database with just one table 'users' containing two fields, 'id' and 'email' respectively. If you are not comfortable with creating simplest of Access databases then you might want to read the database tutorial I have compiled for you. Note that at the end of this article you can download the sample database and code mentioned in this article. Open Microsoft Access and create a database 'mail.mdb' and save it in the same directory where you are creating other HTML and ASP files for this tutorial. In 'design view' of Microsoft Access our 'users' table will look like :

Users - Table
Users - Table

Ok, we've completed first two steps. Now we'll move on to the next page where we will create 'admin' page and an email deletion page from where users can delete their email addresses from your database.

We have created an HTML Form to receive user's email address, an ASP action page to insert that email address into the database and an Access database to receive and store those email addresses. We will now create an admin page from where we can send emails to all the users on our mailing list at once and an email deletion page from where users can delete their email addresses if they later want to.

HTML Admin Page
Create a new HTML page and paste following lines in it's 'body' section :

<p align="center">ADMIN PAGE</p>
<form action="admin_ac.asp" method="post">
Subject :<br>
<input type="text" name="subject"><br><br>
Message :<br><br>
<textarea name="message" cols="60" rows="15"></textarea><br>
<input type="submit" value="send">
</form>

Save it as 'admin.htm'. All it will do is to provide you with an online Form from where you can send messages to all the users of your mailing list.

ASP Admin Action Page
This ASP page will receive the contents of above 'admin.htm' page and will send the actual emails to all the users. Copy and paste the following lines of code into a new page and then save it as 'admin_ac.asp' in the same directory where you have been saving the other pages :


 ( 1 Remaining ) Next

Comments/Questions ( Threads: 33, Comments: 64 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. Adding an image/ logo to newsletter
  2. CDONTS to CDSYS
  3. Unreceived Emails
  4. Email confirmation
  5. Newsletter works!
  6. I am new to Asp,Asp.net ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  7. Cannot get the files to work ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  8. Checking for duplicate users
  9. can't seem to get it to work!
  10. admin problem
  11. Tutorial on Creating Own Newsletter
  12. how to send email using smtp if I was connecting to proxy server?
  13. Deleting e-mail address
  14. Error when sending
  15. path to server
  16. Error on CDonts.newmail object at admin_ac page
  17. Help me in creating the Contact us form
  18. Adding Username field to email.
  19. Adding date to e-mail news letter script created by Faisal Khan
  20. Inserting to database problem
  21. Error message: /mail_ac.asp, line 24 ( 1 Reply )
  22. ASP Tutorial -
  23. Number of emails ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  24. Server object error ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  25. email not sent to everyone ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  26. error '80020009'
  27. Need help! ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  28. Not complete
  29. receive internal error 500 ( 4 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  30. Just to say thanks ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  31. Sending html News Letter ( 5 Replies ) This thread contains 2 replies by the Author of this Article. This thread contains 2 replies by Faisal Khan.
  32. admin problem ( 7 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  33. Inserting to database problem ( 7 Replies ) This thread contains 3 replies by the Author of this Article. This thread contains 3 replies by Faisal Khan.

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.