Asp. NET send email Complete instance

Source: Internet
Author: User
Tags mailmessage net send

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对象列表,主要就是对这个对象集合的一个引用

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.