Original address: http://www.cnblogs.com/panthervic/archive/2012/08/08/2629068.html
The above article is very straightforward to post the code, but some properties and for the whole, if you know some specific properties, you can view the following page
http://blog.csdn.net/qianjiu/article/details/5547061
protected voidButton3_Click (Objectsender, EventArgs e) { //Simple Mail Transfer Protocol classSmtpClient client =NewSmtpClient (); Client. Host="smtp.163.com";//Mail ServerClient. Port = -;//the port number on the SMTP host, which is by default.Client. Deliverymethod = Smtpdeliverymethod.network;//How messages are sent: sent over the network to the SMTP serverClient. Credentials =NewSystem.Net.NetworkCredential ("vichin278","james123");//credentials, the user name and password of the sender's logon mailbox. Attention!!! The password here will not be your email login password, but the authorization password//e-mail message classMailAddress fromaddress =NewMailAddress ("Xiao Ming @163.com","Xiao Ming");//Sender Email, this is displayed in the mailbox, [from: Xiao Ming < xiao Ming @163.com>]MailAddress toaddress =NewMailAddress ("Xiao Qiang @qq.com","Xiao Qiang");////Recipient Email, this is displayed in the mailbox, [to: Xiao Qiang< Xiao Qiang @163.com>;]MailMessage msg =NewMailMessage (fromaddress, toaddress);//Create an e-mail class;Msg. Subject ="Happy Helloween";//Message Subject
//here is the Web page sent by mail. //string filePath = Server.MapPath ("/index.html");//the content of the message can be an HTML text. //System.IO.StreamReader read = new System.IO.StreamReader (FilePath, System.Text.Encoding.GetEncoding ("GB2312")); //string mailbody = read. ReadToEnd (); //read. Close (); //Msg. Body = Mailbody; //Msg. Isbodyhtml = true;//whether the message content is in HTML format
Msg. Body="This is my Halloween blessing to you, still look like! ";//Message Subject ContentMsg. subjectencoding = System.Text.Encoding.UTF8;//Message Subject Code//Msg. bodyencoding = System.Text.Encoding.GetEncoding ("GB2312"); //Message content EncodingMsg. Priority= Mailpriority.high;//message priority (high, normal, low three types respectively)//Msg. Bcc.add ("[email protected]"); //add a CC to a messageAttachment ATC =NewAttachment (@"F:\HappyHelloween.cs");//add an attachment to a messageMsg. Attachments.Add (ATC); Client. Send (msg);//send the message outResponse.Write ("<script>alert (' Success! ') </script>"); }
A post on the licensing password issue http://bbs.csdn.net/topics/391884052
How do I get the authorization code? Login NetEase mailbox → settings → more settings → client authorization password
After setting the authorization password, in the code, use that password, not the password of the login mailbox.
C # Send mail