C # Send mail

Source: Internet
Author: User
Tags ming mailmessage smtpclient

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

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.