Original address: http://www.cnblogs.com/ForEvErNoME/archive/2012/06/05/2529259.html (with code download, bloggers are really ethical)
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>//E-mail///</summary>/<param name= "MailTo" > the mailbox to be sent </param& Gt <param name= "Mailsubject" > Email subject </param>//<param name= "mailcontent" > Mailbox contents </param>//&L T;returns> returns the result of sending a mailbox </returns> public static bool SendEmail (string mailto,string mailsubject,string Mailcontent) {//Set the sender's mail information, such as using NetEase's SMTP string smtpserver = "smtp.163.com";//smtp Server string mail from = "[email protected]"; Login user Name string UserPassword = "XXX";//Login password//Mail Service Settings SmtpClient smtpclient=new smtpclient (); Smtpclient.deliverymethod = smtpdeliverymethod.network;//Specifies how e-mail is sent smtpclient.host = SmtpServer; Specify SMTP Server Smtpclient.credentials = new System.Net.NetworkCredential (Mailfrom, UserPassword);//user name and password//send Mail settings MailMessage mailmessage = new MailMessage (Mailfrom, mailTo); Sender and Recipient Mailmessage.subject = mailsubject;//Subject Mailmessage.body = mailcontent;//content mailmessage.bodyencoding = encoding.utf8;//Body Encoding mailmessage.is bodyhtml = true;//is set to HTML format mailmessage.priority = mailpriority.low;//priority try {SmtpClient . Send (MailMessage); Send message 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:
Example download
Asp. NET send e-mail (GO)