This article illustrates the many possibilities of sending emails in asp.net, covering such aspects as email format, priority, attachment and email encoding.
Asp. NET is given a new object to send email, named SmtpMail. When you use the SmtpMail object to send e-mail from a asp.net page, you can follow these simple steps:
▲ contains the namespaces required for the class of the message;
▲ example an information object, set the attribute;
▲ send a message using the Send method of the SmtpMail object instance.
Now we're going to take a step-by-step look at the process of sending emails from a asp.net page. We use VB to illustrate this example, the final will include VB and C # complete code.
First step: Include namespaces
Introduce the System.Web.Util namespace in the ASP.net page, which includes all the objects necessary to send an email. These objects are:
SmtpMail:代表邮件系统,用于发送email。
MailMessage:代表一个信息,其属性包括发件人地址、收件人地址等。
MailFormat:代表信息的格式:HTML、文本等。
MailAttachment:代表一个email附件。
MailEncoding enum:代表Base64 或Uuencode的任何编码。取值范围:Base64、UUencode
MailPriority enum:用来为信息设置优先权。值为:高、低、一般。
<% @Import Namespace = "System.Web.Util" %>
Step Two: Example MailMessage object
Use the following statement to sample the MailMessage object:
Dim Mailobj as New MailMessage
Prepares the message with the properties of the MailMessage object. The MailMessage object has the following properties:
From:发件人的Email地址
To:收件人的Email地址
Subject:email的主题
Body:email的主体
CC:email抄送的收件人列表
BCC:email暗送的收件人列表
Priority:信息的优先权:高、低或一般
BodyEncoding:信息体的编码,如果有的话,就是Base64或UUencode
BodyFormat:信息的格式:Html 或text
Attachments:附加到email 的MailAttachment对象列表,主要就是对这个对象集合的一个引用