Create mailing lists with ASP

Source: Internet
Author: User
Tags iis odbc reset trim valid email address domain domain name all mail
Talking about sending emails, we always think of mail client software, such as Outlook Express, Foxmail (the latest version of 3.0 Beta1 was released on April 30, please go to http://www.aerofox.com/download) and so on. If you send email on the Web, you will certainly think of some free e-mail, such as the famous www.163.net, so how to implement on the web to send email? You may think that the first installation of mail server, such as Exchange, in fact, NT Server4.0 plus IIS4.0 on it, this article is to illustrate the technical implementation of a practical method.

Mailing Lists (maillist) are more widely used on the Internet. Use mailing lists to keep a positive relationship with your visitors, to send information quickly, easily, and cheaply, and to improve the visibility of your site. The expanded mailing list can also be used to create electronic magazines (like Soyi: http://www.soim.online.sh.cn/). It makes sense to explore the establishment of mailing lists, and our example is to create a mailing list.

First, the principle of e-mail delivery

The implementation of the mail delivery process starts with a client software such as Microsoft Outlook Express that sends a message to an SMTP server, and then the SMTP server is responsible for deciding how to dispose of the message.

If the destination of an e-mail message is the local domain of the server (such as sending an e-mail message to harrizon@domain.com and the SMTP server is smtp.domain.com), the message is stored on the server, or the message is forwarded to another appropriate server.

All SMTP servers on the network can communicate with each other through a "language", the common language being the SMTP protocol. But how does the server decide which destination to deliver the message to? You can find a domain through its domain name resolution system (DNS).

NT Server is a more extensive network server currently in use, and the outlook is promising, and IIS (Internet Information Server4.0,internet Information Server) is a network file and application server that uses HTTP, Gopher and FTP provide services over the Internet or intranet.

The IIS SMTP service provides only message delivery, and it cannot service incoming mail. Microsoft has added a special component to IIS-collaboration Data Objects for Microsoft Windows NT Server, also known as the CDO for NTS Library, which provides mail objects, These objects can be used in ASP (Active Server Pages) scripts to access and process e-mail messages sent to specific users.

A mailing list is a collection of emails from visitors on the web, which sends certain information to the Subscriber on a regular basis when needed. The job you need is to collect emails and send emails. Below we can see how to do this work.

Ii. send e-mail from a Web page

With IIS SMTP and CDO for IIS, you can send e-mail directly to anyone on the Internet from an ASP script.

To install the Microsoft NT ser-ver4.0 First, and then install IIS4.0, be sure to note that the SMTP service is installed by default. After installation, you may want to see if there is a file Cdonts.dll in the Winnt\System32 directory. If this file exists, the installation process is declared successful.

Program 1 is the simplest e-mail program that sends a message with a theme of subject, content test, to ivan@188.net from the mailbox harrizon@163.net.

<%

Dim Mailobject

Set mailobject = Server.CreateObject ("CDONTS. NewMail ")

Mailobject.send "Harrizon@163.net", "ivan@188.net", "Subject", "Test"

%>

  

While such programs can quickly test for success, the utility value is not high. We will optimize it, according to the characteristics of the mailing list, a practical value of the program.

First, use Access to create a database Mail.mdb, used to save an email address; then you need to set up a table, the name of the table is mail, contains a field email (field name email, data type: text, field length: 50), you can also have an ID (field name: ID, data type: From Move number, this field can not be. Set up ODBC, and in Control Panel, double-click the ODBC icon to set up a DSN named Mail.

Now that the Setup section is complete, write the program.

Add program 2 to the appropriate location on your home page. The purpose of program 2 is to collect emails from visitors.

<form method= "POST" action= "addmail.asp" >

<p> your email:<input type= "text" name= "email" size= "><input type=" Submit "

Value= "Subscribe" name= "B1" ><input type= "reset" value= "rewrite" name= "B2" ></p>

</form>

Open the program with the browser 2 get results as shown in Figure 1, fill in a valid email address and click "Subscribe". The server automatically invokes the program 3, the input email will be automatically stored, you may as well use access to open the database directly mail.mdb to see whether the email has just been saved.

(Figure ASP-1) Figure 1

<%

Email=trim (Request ("email"))

Set connection=server.create-object ("ADODB. Connection ")

Connection.Open "Mail", "" "," "

Sql= "INSERT into mail (email) VALUES (' +email+" ') "

Set rs=connection.execute (SQL)

Response.Write Email%> Thank you for joining!

The purpose of program 3 is to save the email to the database Mail.mdb.

Email warehousing means there are subscribers, and now we can go to the next step-send the mail to the Subscriber.

Here we use two programs (SendMail. asp,mail.asp) To complete this part of the work, The role of sendmail.asp is to generate an interface (see Figure 2), where we can choose to send the object (all or part), fill in the sent subject and content, can also paste the attachment, completed after the click "Send Mail", at this time for the administrator, all work is over, But how do you send mail? We'll need to call the program 5.

Program 5 is for sending mail handler mail. Asp. Its role is to send mail, of course, according to the program 4 selection and input to deal with the message. The complete source code for program 5 is www.pccomputing.com.cn the website of electronic and computer.

Program 4 sends e-mail sendmail.asp online. The results of the program run are shown in Figure 2.

(Figure ASP-2) Figure 2

(Procedure 4)

<% Set connection=server.createobject ("ADODB. Connection ")

Connection.Open "Mail", "" "," "

Sql= "SELECT * from Mail"

Set rs=connection.execute (SQL)

sql1= "SELECT COUNT (*) from Mail"

Set Rs1=connection.execute (SQL1)

%>

<form method= "POST" action= "mail.asp" >

<table border= "1" width= "100%" >

<tr bgcolor= "#abcdef" >

&LT;TD align= "Middle" >  play *<%=rs1 (0)%> subscriber <inputtype=

' checkbox ' name= ' All ' value= ' 1 ' checked>
Rs.eof%>

<font size= "3" >

<input type= "checkbox" Name= "Shou" value= "<%=rs (0)%>" >

<%=rs (1)%>

<%

Rs.movenext

Loop

%> </td> </tr>

<tr bgcolor= "#eeddff" >

&LT;TD width= "7%" >

Mail Subject: <input type= "text" name= "subject" size= "><br>"

Message content:<br>

<textarea rows= "9" name= "Body" cols= "></textarea><br>"

Your mail:<input type= "text" name= "Usemail" size= "value=" >

<br> Accessories: <input type= "file" maxlength= "Name=" Attfile "size=" "value=" "> Attachment name: <input type=" Text " Name= "FName" size= "value=" "><br></p>

<input type= "Submit" value= "Send Mail" name= "B1" ><input type= "reset" value= "rewrite" name= "B2" ></p> </td >

</tr>

</table>

</form>

  

(Procedure 5)

<% Shou=trim (Request ("Shou")) ' Get the content selected and entered in program four

Subject=trim (Request ("subject"))

Body=trim (Request ("body")

Att_file=trim (Request ("Attfile"))

Fname=trim (Request ("fname"))

Usemail=trim (Request ("Usemail"))

Ckall=request ("All")

If Ckall=1 then ' is to send mail to all Subscribers

Set conn2=server.createobject ("ADODB. Connection ")

Conn2.open "MAIL", "" "" ' Open Database

Sql2= "SELECT * from Mail"

Set Rs2=conn2.execute (SQL2) ' reads all mail addresses from the database

Do as not rs2.eof

Item=rs2 (0)

Set conn=server.createobject ("ADODB. Connection ")

Conn.Open "MAIL", "" "," "

Sql= "SELECT * from Mail where id=" +CSTR (item) + ""

Set Rs=conn.execute (SQL)

Set mailobject = Server.CreateObject ("CDONTS. NewMail ")

If att_file= "Then ' attachment is empty

Mailobject.send Usemail,rs (1), Subject,body

Response.Write "No attachment Web mail sent successfully!" "

%>
F_name=fname

Mailobject.from=gzer@163.net ' Send a mail address

Mailobject.to=rs (1) ' Recipient

Mailobject.subject=subject

Mailobject.body=body

Mailobject.attachfile Att_file,f_name

Mailobject.send ' Send mail

Response.Write "with Attachment Web mail sent successfully!" "' Send successfully

End If

Response.Write "Receiving Address:" +rs (1) + "<p>"

Response.Write "Theme:" + subject + "<br>"

Response.Write "Content:" + body + "<br>"

%>
Loop

Else

For each item in request ("Shou")

Set conn=server.createobject ("ADODB. Connection ")

Conn.Open "MAIL", "" "," "

Sql= "SELECT * from Mail where id=" +CSTR (item) + ""

Set Rs=conn.execute (SQL)

Set mailobject = Server.CreateObject ("CDONTS. NewMail ")

If att_file= "" Then

Mailobject.send Usemail,rs (1), Subject,body

Response.Write "No attachment Web mail sent successfully!" "

%>
F_name=fname

mailobject.from= "gzer@163.net" ' Email address

Response.Write RS (1) + "<br>"

Mailobject.to=rs (1) ' Recipient

Mailobject.subject=subject

Mailobject.body=body

Mailobject.attachfile Att_file,f_name

Mailobject.send

Response.Write "with Attachment Web mail sent successfully!" "

End If

%>
End If

%>

  

Third, PostScript

1. For the reason of space, some code is omitted here, please understand by the reader.

2. If you send a message with an input field that receives an e-mail address, you can send e-mail to any legal address and the application is more extensive.

3. Use this program can send anonymous mail, but pay attention to do not mess with!

4. If you use the POP3 component, you can receive mail.

5. The attachment of this program does not support Chinese path, the interested person may wish to write better components to support the Chinese path.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.