Asp. NET send e-mail

Source: Internet
Author: User
Tags mailmessage net send smtpclient

1. Supplementary knowledge

(1) What are POP3 and SMTP servers?

Simply put: POP3 is used to receive e-mail, and SMTP is used to send e-mail.

(1) What does POP3 specifically refer to?

POP3 (Post Office Protocol 3) is the 3rd version of the Post Office Protocol, which is a protocol that specifies how personal computers connect to mail servers on the Internet to send and receive mail. It is the first offline protocol standard for Internet e-mail, and the POP3 protocol allows users to store messages from the server on a local host (that is, their own computer) while deleting or saving messages on the mail server based on the client's actions, while the POP3 server is a receiving mail server that follows the POP3 protocol. Used to receive e-mail. The POP3 protocol is a member of the TCP/IP protocol family, defined by RFC 1939

(2) What does SMTP mean specifically?

The full name of SMTP is "Simple Mail Transfer Protocol", which is simply the message Transfer Protocol. It is a set of specifications for transferring messages from the source address to the destination, which controls how messages are relayed. The SMTP protocol is a TCP/IP protocol cluster that helps each computer find its next destination when sending or relaying letters. The SMTP server is the outgoing mail server that follows the SMTP protocol.

2.system.net.mail

You need to reference the System.Net.Mail namespace to send e-mail using ASP. The System.Net.Mail namespace contains classes that are used to send e-mail messages to a Simple Mail Transfer Protocol (SMTP) server for delivery.

(1) There are three more major classes under the namespace:

MailMessage: Provides properties and methods to create a mail message object, which is the message content.

Attachment: Provides properties and methods to create a message attachment object, which is a message attachment.

SmtpClient: Transfers the e-mail message to the SMTP host that you specified for mail delivery.

(2) MailMessage class:

From: The address of the sending message
To: The address of the receiving message
Subject: The title of the message
Priority: Messages are prioritized (for High,low,normal, respectively)
Attachments: An attachment collection of data for an e-mail message
BCC: Secret delivery address
CC: CC Address
Body: Message body
Subjectencoding: The encoding used for the subject content of the e-mail

Isbodyhtml: Whether the message body is an Html-formatted value

Detailed reference: MailMessage

(3) Attachment class:

Detailed reference: Attachment

(4) SmtpClient class:

Deliverymethod: Specifies how outgoing e-mail messages are processed

The name or IP address of the host that host:smtp the transaction

Credentials: Set Credentials to verify sender identity

Detailed reference: SmtpClient

3.ASP. Net send mail two ways

(1) Sending mail via SMTP from the mail service provider

First, you need to register the corresponding service provider free mailbox, because you want to use the Mail service provider's SMTP, they need to authenticate the identity, so as to avoid the generation of large amounts of junk e-mail.

There are three important messages: SMTP server, user name, password. From the online collection of several classes, you can refer to the next.

#region    /// <summary>    ///Send mail/// </summary>    /// <param name= "MailTo" >the mailbox to send</param>    /// <param name= "Mailsubject" >Mailbox Subject</param>    /// <param name= "Mailcontent" >Mailbox Content</param>    /// <returns>returns the result of sending a mailbox</returns>     Public Static BOOLSendEmail (stringMailTo,stringMailsubject,stringmailcontent) {        //set the sender's mail information, such as using NetEase's SMTP        stringSmtpServer ="smtp.163.com";//SMTP Server        stringMailfrom ="[email protected]";//Login User Name        stringUserPassword ="XXX";//Login Password//Mail Service SettingsSmtpClient smtpclient=NewSmtpClient (); Smtpclient.deliverymethod= Smtpdeliverymethod.network;//specify how e-mail is sentSmtpclient.host = SmtpServer;//Specify the SMTP serverSmtpclient.credentials =NewSystem.Net.NetworkCredential (Mailfrom, UserPassword);//user name and password//Send mail SettingsMailMessage MailMessage =NewMailMessage (Mailfrom, mailTo);//Sender and RecipientMailmessage.subject = Mailsubject;//ThemeMailmessage.body = mailcontent;//contentmailmessage.bodyencoding = Encoding.UTF8;//Body Codemailmessage.isbodyhtml =true;//set to HTML formatmailmessage.priority = Mailpriority.low;//Priority Level        Try{smtpclient.send (mailmessage);//Send mail            return true; }        Catch(Smtpexception ex) {return false; }    }

(2) Use SMTP of native SMTP virtual server to send mail

SMTP configuration is required, or the first is simple and practical.

4. Reference: Common mail server

gmail.com:
POP3 Server address: pop.gmail.com
SMTP Server address: smtp.gmail.com

Qq.com:

POP3 Server address: pop.qq.com
SMTP Server address: smtp.qq.com

163.com:
POP3 Server address: pop.163.com
SMTP Server address: smtp.163.com

Sina.com:

POP3 Server address: pop3.sina.com.cn
SMTP Server address: smtp.sina.com.cn

Yahoo.com:
POP3 Server address: pop.mail.yahoo.com
SMTP Server address: smtp.mail.yahoo.com

Sohu.com:
POP3 Server address: pop3.sohu.com
SMTP Server address: smtp.sohu.com

China.com:
POP3 Server address: pop.china.com
SMTP Server address: smtp.china.com


21cn.com:
POP3 Server address: pop.21cn.com
SMTP server address: smtp.21cn.com sina.com:

Asp. NET send e-mail

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.