Here we mainly use Gmail, the reason is because, I use Gmail mailbox to send mail, encountered a small difficulty, and the use of 163 mailbox, did not encounter 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.
The core code is very concise, as follows:
Copy Code code as follows:
String to = "Fill in the recipient's email address here";
String from = "Fill in the sender's email address here";
String subject = "topic for writing messages here";
String BODY = @ "Write the contents of the message 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 the code shows, this email is a simple thing to do. In particular, it is because there are a few small places that are worth paying attention to, otherwise, they will feel puzzled.
First, the Gmail account that is used to send email needs to turn on the pop feature.
Second, pay attention to Gmail's use of the port number, there are 465 and 5,872 (there are no other, I did not go to the careful investigation, if omitted, please Haihan). According to Gmail's documentation, I started with Port 465, always timed out, and the message was not sent successfully. However, when I use Outlook, I also use port 465 to send and receive messages successfully. That's confusing me. After a round of wandering, get a new port number, 587. In asp.net, we use port 587 to send mail successfully. I don't understand why Gmail's documentation only mentions 465 and ignores 587.
I hope it will help you.