1. Tools and resources used: VS2012 provides SmtpClient class (System.NET.Mail) in the. NET Frameword class Library
2. Operation
3, the specific code implementation is as follows:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using System.Net.Mail; Using System.net.mime;using system.net;using System.IO; namespace windowsformsapplication1{public partial class Form1:form {public Form1 () {in Itializecomponent (); }//Based on AI-oriented design private void Form1_Load (object sender, EventArgs e) {} private void btn OK_Click (object sender, EventArgs e) {if (yes. Text = = "" | | txttestname.text== "") {MessageBox.Show ("You did not enter anything!") "); }else try {//To determine the SMTP server address. Instantiate an SMTP client System.Net.Mail.SmtpClient = new System.Net.Mail.SmtpClient ("smtp.qq.com");//pop.ex mail.qq.com//smtp.qq.com Client. Enablessl = true;//Specifies smtpclient use Secure Sockets Layer (SSL) Encrypted connection//Generate a Send address string strfrom = "[email protected]"; Constructs a sender Address object mailaddress from = new MailAddress (strfrom, "Providence", Encoding.UTF8); Constructs a recipient address object mailaddress to = new MailAddress (Txttestname.text, "fate", Encoding.UTF8); Constructs an email message object MailMessage message = new MailMessage (from, to); Add message subject and content message. Subject = "Subject: Smina user test!" " ; Message. subjectencoding = Encoding.UTF8; Message. Body = "Content: Test message" + Yes. Text; The text that is sent by the user enters a message. bodyencoding = Encoding.UTF8; Sets the message client. Deliverymethod = Smtpdeliverymethod.network; Message. bodyencoding = System.Text.Encoding.UTF8; Message. Isbodyhtml = true; Set the user name and password. Client. useDefaultCredentials = false; string username = "[EmaiL protected] "; Your email account string passwd = "IPZUUXXXXXBJJB";//Your authorization code, your password can not be logged in, the authorization code for a serial number such as esscncukoftqe**** application address https://mail.qq . com///User login information NetworkCredential mycredentials = new NetworkCredential (username, passwd); Client. Credentials = mycredentials; Send mail client. Send (message); MessageBox.Show ("Mail sent successfully, thank you for your support!") "); } catch {MessageBox.Show ("message sent Failed"); } } }}
4, simple send the function of the mail to realize! Please give us a lot of advice!!! Thank you!!!!
5. Acknowledgement: Thanks to the vast number of Bo friends have selfless dedication!
Send a message in a wave of C #