Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Stardeveloper RSS Feed
Newsletter
Enter your email address below to be informed every time a new article is posted at Stardeveloper.com:

You can follow Faisal Khan on Twitter
Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (10)
  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

Hosted by Securewebs.com
 
Home : .NET : ASP : An ASP Tutorial to create your own News Letter
 
	<%
' Declaring variables
Dim rs, mail, subject, message, data_source, sql_select, no
no = 0
subject = Request.Form("subject")
message = Request.Form("message")
' Adding a link to all messages by which users can delete their
' emails if they would want later
message = message & vbcrlf & vbcrlf
message = message & "To stop receiving emails click here :" 
message = message & vbcrlf
message = message & "http://yoursite.com/urfolder/del.asp?email="
sql_select = "select email from users"
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 

	Server.MapPath("mail.mdb")
' Check to see if you have not pressed the 'send' button mistakenly
If Len(message) Then
' If you have written some message then lets send it
' You can use  ASP Email component of your choice, here I will
' stick with CDO
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql_select, data_source
While Not rs.EOF
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.From = "webmaster@yoursite.com"
mail.To = rs("email")
mail.Subject = subject
mail.Body = message & rs("email")
mail.Send
Set mail = Nothing
no = no + 1
rs.MoveNext
Wend
' When messages have been sent to all the users, exit
Response.Write "Emails sent to " & no & " users."
rs.Close
Set rs = Nothing
' Had you pressed the button mistakenly with text area empty, then
' redirect back to the HTML Form
Else
Response.Redirect "admin.htm"
End If
	%>

Done sending emails to all the users in our mailing list. Lets now create a 'del.asp' page whose link we have already added in our messages. Users will be able to delete their emails from out database if they want it by clicking the link we provided to them in their emails.

Note if you are getting errors when testing this script on your own computer, then search in the 'windows/sytem/' diretory ( win95/98 users ) or 'winnt/system32' directory ( winnt/2000 users ) if 'cdonts.dll' is present there or not. If it's not then get it from the Windows CD or search it on www.microsoft.com. You should change the URL provided in above code for the email deletion page to the URL where that 'del.asp' page will actually reside.

ASP Email Deletion Page
Create a new page and add the following lines of code into and then save it as 'del.asp' in the same folder where you have kept other pages :

	<%
' Declaring variables
Dim email, con, data_source, sql_delete
email = Request.QueryString("email")
sql_delete = "delete email from users where email = '" & email & "'"
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
	
	Server.MapPath("mail.mdb")
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_delete
con.Close
Set con = Nothing
Response.Write "Your email address " & email & _ 
	" was successfully deleted from our database."
	%>

We are now done with creating our ASP based news letter for our site. I have delibrately kept things simple so that beginners can also understand whats going on. You can add your own features to it as you want.

	<%
' Declaring variables
Dim rs, mail, subject, message, data_source, sql_select, no
no = 0
subject = Request.Form("subject")
message = Request.Form("message")
' Adding a link to all messages by which users can delete their
' emails if they would want later
message = message & vbcrlf & vbcrlf
message = message & "To stop receiving emails click here :" 
message = message & vbcrlf
message = message & "http://yoursite.com/urfolder/del.asp?email="
sql_select = "select email from users"
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 

	Server.MapPath("mail.mdb")
' Check to see if you have not pressed the 'send' button mistakenly
If Len(message) Then
' If you have written some message then lets send it
' You can use  ASP Email component of your choice, here I will
' stick with CDO
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql_select, data_source
While Not rs.EOF
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.From = "webmaster@yoursite.com"
mail.To = rs("email")
mail.Subject = subject
mail.Body = message & rs("email")
mail.Send
Set mail = Nothing
no = no + 1
rs.MoveNext
Wend
' When messages have been sent to all the users, exit
Response.Write "Emails sent to " & no & " users."
rs.Close
Set rs = Nothing
' Had you pressed the button mistakenly with text area empty, then
' redirect back to the HTML Form
Else
Response.Redirect "admin.htm"
End If
	%>

Done sending emails to all the users in our mailing list. Lets now create a 'del.asp' page whose link we have already added in our messages. Users will be able to delete their emails from out database if they want it by clicking the link we provided to them in their emails.

Note if you are getting errors when testing this script on your own computer, then search in the 'windows/sytem/' diretory ( win95/98 users ) or 'winnt/system32' directory ( winnt/2000 users ) if 'cdonts.dll' is present there or not. If it's not then get it from the Windows CD or search it on www.microsoft.com. You should change the URL provided in above code for the email deletion page to the URL where that 'del.asp' page will actually reside.

ASP Email Deletion Page
Create a new page and add the following lines of code into and then save it as 'del.asp' in the same folder where you have kept other pages :

	<%
' Declaring variables
Dim email, con, data_source, sql_delete
email = Request.QueryString("email")
sql_delete = "delete email from users where email = '" & email & "'"
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
	
	Server.MapPath("mail.mdb")
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_delete
con.Close
Set con = Nothing
Response.Write "Your email address " & email & _ 
	" was successfully deleted from our database."
	%>

We are now done with creating our ASP based news letter for our site. I have delibrately kept things simple so that beginners can also understand whats going on. You can add your own features to it as you want.


Previous ( 1 Gone )( No Further Pages )

See all comments and questions (post-ad) posted for this tutorial.


Download Associated Files
2000032001.zip

Related Articles
  1. Server Side Email Addresses Validation using VBScript
  2. Sending E-Mails with ASP Pages
  3. Basic Active Server Pages Tutorial for beginners
  4. Extremely useful ASP functions
  5. Uploading Files to the Server Hard Disk using plain ASP
  6. Object Oriented Design Principles in Visual Basic
  7. Beginning E-Commerce : Object Oriented Programming
  8. Professional Windows DNA
  9. An ASP Tutorial to create your own Database driven Search Engine
  10. Connections, Commands and Procedures

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 but no email
  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 to.

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