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.
Sample Download:Files.cnblogs.com/forevernome/%e5%8f%91%e9%80%81%e7%94%b5%e5%ad%90%e9%82%ae%e4%bb%b6.rar
#region
<summary>
Send mail
</summary>
<param name= "MailTo" > Mailbox to send </param>
<param name= "Mailsubject" > Email topics </param>
<param name= "mailcontent" > Mailbox content </param>
<returns> returns the results of the Send 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 mailfrom = "[email protected]"; Login user Name
String userpassword = "XXX";//Login password
Mail Service settings
SmtpClient smtpclient=new smtpclient ();
Smtpclient.deliverymethod = smtpdeliverymethod.network;//Specify how e-mail is sent
Smtpclient.host = SmtpServer; Specify the 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;//Theme
Mailmessage.body = mailcontent;//Content
mailmessage.bodyencoding = encoding.utf8;//Body encoding
mailmessage.isbodyhtml = true;//is set to HTML format
Mailmessage.priority = mailpriority.low;//Priority
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
Introduction to ASP. NET send e-mail