Ways to send messages using SmtpClient _c# tutorial

Source: Internet
Author: User
Tags readline mailmessage smtpclient

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.