C # Use the 163 SMTP server to send emails

Source: Internet
Author: User
Tags mailmessage smtpclient

We all know that System in C. net. mail. the SmtpClient class is used to send emails to the SMTP server. However, if you use a local SMTP server (such as the Local iis smtp server) to send emails, the email address of many large websites is treated as spam, because the address of the local SMTP server is not known, and the sent email is taken as an unknown email, therefore, we need to use SMTP servers of some large well-known websites to send emails to us. Here we will introduce how to use the SMTP server 163 to send emails.

PS: if you use the 163 SMTP server to send emails, the 163 email address will be used as the sender's address for all emails sent by your development system, however, I think this is better than sending emails to users' spam every time, because if all the emails you send are spam emails, the user may not see what you send at all, delete the email, which is the worst ....

Let's take a look at the Code:

System. Net. Mail. SmtpClient client = new System. Net. Mail. SmtpClient ();
Client. Host = "smtp.163.com"; // use the 163 SMTP server to send an email.
Client. usedefacrecredentials = true;
Client. DeliveryMethod = System. Net. Mail. SmtpDeliveryMethod. Network;
Client. credentials = new System. net. networkCredential ("abc", "********"); // The SMTP server of 163 must use the username and password of the 163 mailbox for authentication, if you do not need to apply for 163 applications,
// Assume that you already have an account with a 163 email address. The username is abc and the password is *******
System. Net. Mail. MailMessage Message = new System. Net. Mail. MailMessage ();
Message. from = new System. net. mail. mailAddress ("abc@163.com"); // note that 163 appears to require the sender's email address to be 163, the sender's email user name must be the same as the user name used for SMTP server authentication.
// Because the above user name abc for SMTP Server Authentication, so the sender's email address here should also be written as a abc@163.com
Message. To. Add ("123456@gmail.com"); // send the mail To Gmail
Message. To. Add ("123456@qq.com"); // send the email To the QQ mailbox
Message. Subject = "test ";
Message. Body = "test email Body ";
Message. SubjectEncoding = System. Text. Encoding. UTF8;
Message. BodyEncoding = System. Text. Encoding. UTF8;
Message. Priority = System. Net. Mail. MailPriority. High;
Message. IsBodyHtml = true;
Client. Send (Message );

 

 

Related 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.