Designing efficient mailing lists with asp.net

Source: Internet
Author: User
Tags log log log mail require access database advantage
asp.net| Design | Mailing list an attractive, full-featured Web sites often have the following characteristics: First, the content of a full, practical, to attract the interest of the content of the browser; second, the page is set up reasonably, the page is beautifully designed; The third is the website interaction is strong, the user and the website or the user and the user and the customer exchanges between Four is the website content update timely and may inform the user at the first time. These characteristics may be for some large portal sites, is not particularly suitable, because the characteristics of the portal site, user traffic is often not the difference between the content but user habits, historical reasons and geographical differences (such as the Guangdong area of the browser like NetEase, Beijing's like Sina). And for the general personal website or corporate site, the above features are particularly important, because this kind of site content update is not very fast, visitors to these sites often have a specific purpose (such as looking for specific areas of information or product information), when the content of the site to attract users, The updated information of the website or the latest news of the website is necessary to inform the visitors in time, so as to grasp the visitors tightly, and cultivate the "browsing loyalty" of the visitors. This is the role of the site mailing list.

I. Mailing list function and working mode
What is the mailing list? A mailing list is a Web site or organization that sends messages to all users in a timely manner to inform the relevant users of their emails and to send them to each user when a message needs to be sent. On the surface, mailing lists and e-mail messages used when the "send" and "secret send" similar, basically no difference, in fact, they still have a difference: (1) Mailing list has a clear distribution purpose, send mailing list is to send specific information to specific users (2) Mailing list recipients cannot obtain information from other recipients, which is the biggest difference between mailing lists and e-mail messages. We know that when we get some emails, it is found that there are many other users ' e-mail addresses in the "attached" column of the message, which is to send the message to a series of users via the "Send in" form, and the message sent through the mailing list, the user feels that the sender is sent to the user alone, not the other user's information Of course, this is how it is sent. In this way, we can know that the mailing list works by taking out each user's e-mail and sending the same information one at a a-person.
Since the mailing list is sent individually, then it is certain that we cannot send it by hand, only through the software. Now, the mailing list of the following ways to send, first, through a dedicated mass mail software to achieve, the software will be all e-mail addresses read, and then sent, the advantages of these software can be specific users to change the message subject information or sender mailbox; The disadvantage is that these software often require registration fees And the second is through a dedicated mailing list service to provide Web site implementation, these sites are used by programs to help mailing list publishers to send information to subscribers, which is one of the most common ways for individual users, the advantages of which are simple, free, and the disadvantage is that these services often provide Web site performance is not very stable, mail delays often occur Third, through their own web site design a mailing list program, their own management, the advantage is to send information efficient, easy to manage, the disadvantage is that the technology to achieve a slight advantage of difficulties, not very suitable for the general user. We are here to introduce a full-featured mailing list through ASP.net programming.

Second, the design of mailing list
Before designing, we need to know that all e-mail addresses in the mailing list must be saved into a file, where we keep all e-mail addresses in an Access database, which makes it easy to add, modify, delete, and so on. Here, our database is named Mail.mdb, located in the data directory. The datasheet is named Mail and has only one field, "Mail," for saving e-mail addresses.
As a long term website feature, we certainly require that the message not be sent with a detailed send record and each message sent. Here, we will automatically produce a log log file in HTML format in the log directory using the topic of sending mail for the file name.
Now that we have a basic understanding of the function and file structure of the program, let's look at the program code:
<%@ Page language= "VB" debug= "true" explicit= "true"%>
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.OleDb"%>
<%@ Import namespace= "System.Web.Mail"%>
<%@ Import namespace= "System.IO"%>


<meta http-equiv= "Content-language" content= "ZH-CN" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Mailing List </title>

<style>
<!--
A:link{color: #0066FF; text-decoration:none;font-size: "9 PT"}
A:visited{color: #000066; text-decoration:none;font-size: "9 PT"}
A:actived{color: #FF0000; font-size: "9 PT"}
A:hover{color: #FF0000; font-size: "9 PT"}
Table{font-size: "One PT"}
-->
</style>


<body>

<script language=vb runat= "Server" >
Sub SendMail (Obj as Object, E as EventArgs)
Lbmsg. Text= ""

Dim Mailobj as New MailMessage
Dim SMTP as New smtpmail
' Define the name of the SMTP server
Smtp.smtpserver= "127.0.0.1"
' Define the sending address of the message
Mailobj.from=sendmailbox.value
' Define the receiving address of the message
Dim Conn as OleDbConnection
Conn=connectdb ("Data\mail.mdb")
Conn.Open ()
Dim Reader as OleDbDataReader
READER=READDB (conn, "SELECT * from Mail")

while (Reader.read ())
Try
Mailobj.to=reader ("Mail")

Mailobj.subject =subject.value
Mailobj.body =content.value
' Default send Message format is plain text, if you choose HTML format, set to HTML format
If mode.value= "HTML" Then
Mailobj.bodyformat=mailformat.html
End If
' Set message send level to high
Mailobj.priority = Mailpriority.high

Smtp.send (Mailobj)

Lbmsg.text=lbmsg.text+reader ("Mail") + "ok! Time: "+now (). ToString () + "<br>"
Catch er as Exception
Lbmsg.text=lbmsg.text+er.message+ "<br>"
Finally

End Try
End While
Reader.close ()
Dim Strwriterobj as StreamWriter
Try
strwriterobj= File.createtext (Server.MapPath ("log\") +subject.value+ ". htm")
Strwriterobj. Write ("Catch er as Exception
Lbmsg.text=lbmsg.text+er.message+ "<br>"
Finally
Strwriterobj.close
lbmsg.text=lbmsg.text+ "Log Save success!" Save Directory:<br> "+server.mappath (" log\ ") +subject.value+". htm "
End Try

End Sub

' Link Database
Function Connectdb (txtdatabase as String) as OleDbConnection
Dim Conn as OleDbConnection
Dim ConnStr as String
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=false; Data source= "+server.mappath (txtdatabase)
Connectdb=new OleDbConnection (CONNSTR)
End Function

' Read a record
Function READDB (conn as oledbconnection,txtsql as String) as OleDbDataReader
Dim cmd as OleDbCommand
Cmd=new OleDbCommand (Txtsql,conn)
Readdb=cmd.executereader ()
End Function
</SCRIPT>


<p align= "center" ><font size= "5" face= "italics _gb2312" > Mailing list </font></p>
<div align= "center" >
<center>
<table border= "0" width= "770" >
<tr>
&LT;TD width= "100%" >
<form method= "POST" runat= "Server" >
<table border= "0" width= "100%" height= "a" >
<tr>
&LT;TD width= "15%" align= "right" height= "E" > Email: </td>
&LT;TD width= "85%" height= "><input type=" "Text" Name= "Sendmailbox" id= "Sendmailbox" size= "a" runat= "Server"/ ></td>
</tr>
<tr>
&LT;TD width= "15%" align= "right" height= "a" > title: </td>
&LT;TD width= "85%" height= "><input type=" "Text" name= "subject" id= "Subject" size= "a" runat= "Server"/>< /TD>
</tr>
<tr>
&LT;TD width= "15%" align= "right" height= "a" > Content:</td>
&LT;TD width= "85%" height= "><textarea rows=" "6" name= "Content" cols= "no" id= "content" runat= "Server"/>< /textarea></td>
</tr>
<tr>
&LT;TD width= "15%" align= "right" height= "a" > Way:</td>
&LT;TD width= "85%" height= "><select size=" 1 "name=" mode "id=" mode "runat=" Server ">
<option value= "Text" selected>text</option>
<option value= "HTML" >HTML</option>
</select></td>
</tr>
</table>
<p align= "center" ><input type= "button" value= "Submit" Name= "OK" onserverclick= "SendMail" runat= "Server"/> </p>
</form>
<asp:label id= "lbmsg" runat= "Server"/>
<p>
</td>
</tr>
<tr>
&LT;TD width= "100%" ></td>
</tr>
</table>
</center>
</div>

</body>

The operating interface of the program is as follows (figure I):


In the above program, we will set some of the more common functions into functions, in the main program directly call these functions, so that the program looks more concise, the modification is very simple. Here, let's briefly introduce these functions, one is the Connectdb (txtdatabase as String) that connects to the database, which uses the relative position of the Access database as the function parameter to return the database connection OleDbConnection The function READDB (conn as oledbconnection,txtsql as String) can execute an SQL statement directly and return to OleDbDataReader. In the program, we save the results sent by each message and preferably generate an HTML-formatted log file. We need to introduce "System.Data.OleDb", "System.Web.Mail" and "System.IO" when we introduce namespaces, because we use databases, emails, and file operations in our programs.
In the use of the above mailing list program, we need to pay attention to a few issues, the first is the SMTP server settings, we know that the SMTP server is a mail server, and now some free mail providers are no longer providing SMTP services for all messages, when sending mail, need to authenticate user information , and we see that in the above program even the entire ASP.net mail part, does not consider the SMTP user authentication problem, so that we can not use an SMTP server, and must use a completely free SMTP server, such servers are now very few. So, if there are conditions, it is best to set up our own computer for the SMTP server, how to achieve, we can download Easymail software. The second is the speed of mail delivery, if the SMTP server on the local computer, send fast, basically do not worry, if not the local server, then it is best not to send too much, one is the speed problem, the second is to send too many messages, the SMTP server may be considered spam and denial of service, We can test it ourselves; the third is the problem of setting up the sender of the mail, Through this program or by using the ASP.net mail function, we can easily write in the mail, so that people with ulterior motives can use this function to send spam, of course, these e-mail tracking source is very simple, direct check IP can, random, we'd better not send at will.

Third, summary
Above we use a concrete example to introduce the complete mailing list design, the program completely according to the actual need design, has the bigger practicability. In the program implementation, we also use the database, mail and file operations, involving more content, interested friends can be in accordance with their actual requirements of the appropriate modification, so that the program functions more comprehensive.



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.