ProgramYes:
CopyCode The Code is 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, );
Client. Send (Message );
Console. Readline ();
}
When running, the message "unable to connect because the target computer is actively rejected" is reported ." . It is said that the SMTP service was not started. So I found the setting method on the internet, control panel-> program and function-> enable or disable WINDOWS function-> Internet Information Service-> application development function-> -〉.. Net scalability. Then, an SMTP Email item appears in the IIS manager. After setting the parameters, the results are still the same.
After studying it again, iis7 in Windows 7 has already removed the SMTP service, so no matter how you set it, it is useless. (We will discuss it here)
The solution is to install a third-party SMTP server. For example, free SMTP server.
After installation, you do not need to set any settings. Start the SMTP server and then run the above program. Everything is normal.
If you want to use third-party SMTP servers such as Netease to send emails, it is also very easy. Slightly modify the code:
Copy code The Code is as follows: static void main (string [] ARGs)
{
Smtpclient client = new smtpclient ();
Client. Host = "smtp.163.com ";
Client. Credentials = new networkcredential ("usenme", "password"); // required
Mailaddress from = new mailaddress ("from@163.com ");
Mailaddress to = new mailaddress ("to@test.com ");
Mailmessage message = new mailmessage (from, );
Client. Send (Message );
Console. Readline ();
}
This attempt took a lot of time. I hope other people can see this Article .