Here we mainly use Gmail. The reason is that when I use a Gmail mailbox to send emails, I encounter a small difficulty. When I use a mailbox such as 163, you have not encountered this problem.
In ASP. net2.0, sending mail is very simple. We mainly use several classes from the namespace system. net. Mail, mailmessage and smtpclient.
Core Code Is very concise, as follows:
Copy code Code: string to = "Enter the recipient's email address here ";
String from = "Enter the sender's email address here ";
String subject = "the subject of the email written here ";
String body = @ "the email content here ";
Mailmessage message = new mailmessage (from, to, subject, body );
// Smtpclient client = new smtpclient ("smtp.gmail.com", 465 );
Smtpclient client = new smtpclient ("smtp.gmail.com", 587 );
Client. Credentials = new networkcredential ("Gmail account", "Gmail password ");
Client. enablessl = true;
Client. Send (Message );
As shown in the code, it is very easy to send an email. It is especially mentioned here because there are a few small points worth noting. Otherwise, it will be puzzling.
First, you need to enable the pop function for the Gmail account used to send emails.
Secondly, pay attention to the port numbers used by Gmail, which are 465 and 587. (if there are any other ports, I did not investigate them carefully. If there are any omissions, please refer to Hai Han ). According to the instructions in Gmail, I used port 465 at first and always timed out. The email cannot be sent successfully. However, when I use outlook, port 465 is also used to successfully send and receive emails. This confused me. After hovering around, you can get a new port number, which is 587. In ASP. NET, we use port 587 to successfully send emails. I don't understand why Gmail only mentions 465, but ignores 587.
Hope to help you