Build a complete E-mail sending system with ASP.NET
Author: Wang Tian article taken from: CCID January 21, 2002
If you want to use ASP to do an E-mail sending system, you must first think of the components developed by third parties, but this will take much silver. Of course, you can also transfer E-mail with Windows's own object - CDONTS.NEWMAIL object, which is free, but it is very dependent on the operation platform, and the cdonts.newmail object exists only Windows 200 and NT, in Windows. Under 95/98 is there is no such object.
Since Microsoft launched ASP.NET, E-mail sent has become a basic object for web programming. This article is to discuss how to make a functional very complete E_MAI sending system.
One. Development and Run Platform Windows 2000 Professional, .NET Framework Beta 2
two. What kind of E-mail sending system is a functional system only if a mail sending system has: recipient address, sender address, CC address, delivery address, email topic, mail body, and attachment, etc. When the function, this mail sending system is a relatively complete system. The specific function is shown below:
The specific steps of implementing these functions will be described below.
three. The Specific Implementation Step First, you must introduce a Class Library (class library) sent by E-mail in the .NET Framework SDK - System.Web.mail. This class library provides all objects, properties, and methods sent by e-mail. The most important object is the MailMessage object and the SMTPMAIL object. The MailMessage object is mainly a structure in which the E-mail is packaged. Such as: recipient address, sender address, etc. The SMTPMAIL object is mainly to send the MailMessage object that has been defined. Here are some important steps to specify: 1. To define the MailMessage object, you first create a MailMessage object. A MailMessage object can be created by the following statement. <% @Import namespace = "system.web.mail" Dim Mailobj As New MailMessage ()%>
2. With a MailMessage object, let's define the structure of the email below. We define one by one according to the mail structure sequence of the above figure. 1>. Message: mailobj.form = "Send Address" 2>. The destination address of the message: mailobj.to = "Destination address" If you want to send multiple people, separate each email address with a comma. 3>. 邮 地址 地址: mailobj.cc = "Cc address" is the same, if you want to send it to multiple people, you can write a plurality of email addresses on the "Cc address", but use a comma They separate. 4>. Mailpool address: mailobj.bcc = "Pass address" desessment address and Cc address Similar 5>. Mail Topic: Mailobj.Subject = "Mail Topic" 6>. Mail content: mailobj.body = "Mail content" 7>. Mail priority: mailobj.priority = mailpriority.normal 'This is defined as ordinary, you can also define high (high), low (low)> definition email Format: mailobj.bodyformat = mailformat.text 'This is defined as a text format, you can also define emails as hypertext formats, only change mailformat.text to MailFormat.html. 9> Add an attachment to the email: people who have used ASP know how difficult it is to browse. But after ASP.NET appears, all this will become simply. Only use the following line of code, you can choose any file of the drive. 3. Send e-mailsmtpmail.smtpserver = "" Specifies to send E-mail using the default SMTP server SMTPMAIL.SEND (Mailobj) '
four. Program full source code <% @Import namespace = "system.web.mail"%>