The procedure is this:
Copy Code code as follows:
static void Main (string[] args)
{
SmtpClient client = new SmtpClient ();
Client. Host = "localhost";
MailAddress from = new MailAddress ("from@test.com");
MailAddress to = new MailAddress ("to@test.com");
MailMessage message = new MailMessage (from, to);
Client. Send (message);
Console.ReadLine ();
}
The runtime will report "because the target computer is actively rejecting and cannot connect." "The mistake. I checked. The SMTP service is said to be not started. So on the internet found a way to set up, control Panel-〉 programs and features-〉 turn on or off Windows features-〉internet information Services-〉 application development features-〉. NET extensibility, put this item on the hook. You will then receive an SMTP e-mail entry in IIS Manager. After trying to make the relevant settings, the result is the same error.
Again, the original Windows 7 IIS7 has removed the SMTP service, so it is futile to set it anyway. (Here are the relevant discussions)
The workaround is to install a third-party SMTP server. Free SMTP Server, for example.
After the installation without any settings, start the SMTP server, and then run the above program, all normal.
If you want to use NetEase and other Third-party SMTP server to send mail, is also very simple. Code slightly modified:
Copy Code code as follows:
static void Main (string[] args)
{
SmtpClient client = new SmtpClient ();
Client. Host = "smtp.163.com";
Client. Credentials = new NetworkCredential ("Usenme", "password");//Must be set
MailAddress from = new MailAddress ("from@163.com");
MailAddress to = new MailAddress ("to@test.com");
MailMessage message = new MailMessage (from, to);
Client. Send (message);
Console.ReadLine ();
}
The attempt took a lot of time and hopefully others will be able to help when they see this article.