C # Sending emails to local services (code implementation ),

Source: Internet
Author: User
Tags mailmessage smtpclient

C # Sending emails to local services (code implementation ),
Preface

In the past few days, the billing system requires a mailbox to retrieve the password! Here we will share with you. There are many implementation methods. This blog mainly shares the methods sent by the local server.

Method

Using System. Net; using System. Net. Mail ;////// Send the verification code by email ///Public void SendMail () {System. net. mail. smtpClient client = new System. net. mail. smtpClient (); client. host = "smtp.163.com"; // use the 163 SMTP server to send the email client. usedefacrecredentials = true; client. deliveryMethod = System. net. mail. smtpDeliveryMethod. network; client. credentials = new System. net. networkCredential ("157 *** 1797@163.com", "0713yj"); // The SMTP server of 163 needs to use the username and password of 163 mailbox as authentication System. net. mail. mailMessage Messa Ge = new System. net. mail. mailMessage (); Message. from = new System. net. mail. mailAddress ("157 *** 1797@163.com", "every day to see online cafe customer service", System. text. encoding. UTF8); // note that 163 indicates that the sender's email address must be 163, in addition, 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 is used for SMTP Server Authentication, so here the sender's email address should also be written as abc@163.com // Message. to. add ("123456@gmail.com"); // send mail to Gmail Message. to. add (txtEmail. text. trim (); // send the email to the QQ mail Message. subject = "retrieve password"; // mail title Message. Body = "Hello! "+ SystemVarify +" is the verification code for your identity verification, used to retrieve the login password. "; // Mail content 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 );}
Conclusion

The sender's email password and sender content can all be written to the configuration file. For how to modify and add a configuration file, go to [C #] to read and modify the configuration file.

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.