Personalized mail delivery system with asp.net-practical tips

Source: Internet
Author: User
Tags mailmessage
I. Operating Environment

Although Microsoft Company has launched Visual Studio. NET has been for some time, but the. NET Framework SDK is still beta, Beta 1 and Beta 2, respectively. There is a big difference between these two versions, for example, many namespaces (NameSpace) have different names. We are here to select Beta 2. The operating system is the Windows Professional version.

Two. Basic knowledge

First of all, introduce a message to send the system to use some knowledge.

(a). First of all, briefly understand the protocol to be used in the program-Simple Mail Transfer Protocol (Simplicity Mail Transfer Protocol)--smtp, SMTP server, is used to send mail and transit mail. To mention his sister brother. Post Office Agreement 3 (Postoffice Protocol 3)--pop3. The POP3 server is used to receive mail, and the Mail on our account is saved on this class of servers. Since we're only introducing the message in this article, it's only SMTP that's involved.

(b). Let's take a look at the namespace (NameSpace)--system.web.mail We use in the program (note: the. NET Framework SDK Beta 1 is called System.Web.Util). In this big class library provides the rich object, the attribute, the method regarding the mail sends, is he makes the sending mail to become a very relaxed, the joyful matter. The following is a brief introduction to the specific uses of each object, attribute, and method:

(1). Object

There are three main objects used to send mail in the System.Web.Mail namespace, namely, SmtpMail, MailMessage, MailAttachment. Where smtpmail is setting up an SMTP server, by which he chooses which server to use to send mail. MailMessage is the richest of the three objects, and a large number of attributes are packaged into our present mail components, and the MailAttachment objects correspond to the attachments in the message.

(2). property

Within the System.Web.Mail namespace is the most abundant and important attribute of the MailMessage object, and the following table is his main attribute, which is directly related to our sending message:

Attribute names represent meaning
From Source Address
To Destination Address
Subject Message Subject
Priority message priority (high, low, Normal)
Attachments Accessories
BCC Dark Send Address
CC CC Address
Body Message Content Subject
BodyFormat message Format (html,text)
Bodyencoding Mail Encoding (Base64, UUencode)

(3). method

The most important method in the System.Web.Mail namespace is the Send method of the SmtpMail object, in which the message is sent by calling him. There are two ways of his invocation:

I> direct call

The Send method for the SmtpMail object can be invoked as long as there are four parameters, that is, you can send an e-mail message if you have four correct parameters. The specific call format is as follows:

Smtpmail.send ("Mail Source Address", "Mail Destination Address", "Mail Subject", "Mail Content")


But this call is too simple to meet the simple message sent, for complex messages, you need to use the second method to invoke:

Ii> The MailMessage object is invoked as a parameter, as follows:

Smtpmail.send (MailMessage)

Because the MailMessage object has more properties, this call makes the message more informative, which is generally used to send messages. In the following example, this is the calling method.

Three. Design ideas and steps:

The first thing to explain is that the program language we use in this asp.net program is Visual Basic. NET.

First step: To include the namespace System.Web.Mail, add the program language type used in the program:






Step Two: Initialize SmtpMail, MailMessage objects:

Dim Mailobj as New MailMessage

Dim SMTP as New smtpmail

' Define the name of the SMTP server

Smtp.smtpserver= "Smtp.yeah.net"

' Define the sending address of the message

Mailobj.from = "Zhangchulan@yesky.com"

' Define the receiving address of the message

mailobj.to = "Majinhu@yesky.com"

' Define a message's dark-sending address

Mailobj.bcc= "Majinhu@163.net"

' Define CC addresses for messages

Mailobj.cc= "Majinhu@yesky.com"

' Define the subject of the message

Mailobj.subject = "My mail system, welcome to use!" "

' Define the body of the message

Mailobj.body = "Here is the subject of the message!" "

' Messages are sent in HTML format

Mailobj.bodyformat = mailformat.html

' Defines the finite level of the message, which is set to high

Mailobj.priority = Mailpriority.high

' Attach an attachment to the sent message

MAILOBJ.ATTACHMENTS.ADD (New MailAttachment ("C:test.doc"))


Step three: Send mail

Smtp.send (Mailobj)
Four. Program source code

[Tr= #ebe9eb] [Td]<script language=vb runat= ' server ' > <br>
<br>
Sub SendMail (Obj as Object, E as EventArgs) <br>
<br>
Dim mailobj as New MailMessage <br>
<br>
Dim SMTP as New smtpmail <br>
<br>
' Define the name of the SMTP server <br>
<br>
Smtp.smtpserver= "Smtp.yesky.com" <br>
<br>
' Define send address for mail <br>
<br>
Mailobj.from = "Zhangchunlan@yesky.com" <br>
<br>
' Define the receiving address of the message <br>
<br>
mailobj.to = "Majinhu@yesky.com" <br>
<br>
' Define the message's dark send address <br>
<br>
Mailobj.bcc= "Majinhu@163.net" <br>
<br>
' Define CC addresses for messages <br>
<br>
Mailobj.cc= "Majinhu@yesky.com" <br>
<br>
' Define the subject of the message <br>
<br>
Mailobj.subject = "My mail system, welcome to use!" "<br>
<br>
' Define the subject of the message <br>
<br>
Mailobj.body = "Here is the subject of the message!" "<br>
<br>
' Messages are sent in HTML format <br>
<br>
Mailobj.bodyformat = mailformat.html <br>
<br>
' Defines the limited level of mail <br>
<br>
mailobj.priority = Mailpriority.high <br>
<br>
' Attach the previous attachment to the sent message, make sure there is a Test.doc file in the root directory of C disk <br>
<br>
MAILOBJ.ATTACHMENTS.ADD (New MailAttachment ("C:test.doc"))
<br>
<br>
Smtp.send (mailobj) <br>
<br>
End Sub <br>
<br>
</SCRIPT>
[/TD] [/TR]
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.