C # use System.Net.Mail; send mail email

Source: Internet
Author: User
Tags mailmessage

Sending a message is a simple function, but it's often used, and here's the simplest way to write it.

       Remember to quote using System.Net.Mail; <summary>///email///</summary>/<param name= "smtpserver" &GT;SMTP server </pa        ram>//<param name= "UserName" > Login account </param>//<param name= "pwd" > Login password </param>        <param name= "nickname" > Sender nickname </param>//<param name= "Strfrom" > Senders </param>  <param name= "Strto" > Recipient </param>//<param name= "SUBJ" > Topics </param>//<param Name= "Bodys" > Content </param> public static void SendMail (String smtpserver, String userName, string pwd, Strin G Nickname, String strfrom, String Strto, String subj, String bodys) {SmtpClient _smtpclient = new SMTP            Client ();            _smtpclient.deliverymethod = smtpdeliverymethod.network;//Specifies the way e-mail is sent _smtpclient.host = smtpserver;//Specify the SMTP server _smtpclient.credentials = new System.Net.NetworkCredential (UserName, pWD);//username and password//mailmessage _mailmessage = new MailMessage (strfrom, Strto);            MailAddress _from = new MailAddress (strfrom, nickname);            MailAddress _to = new MailAddress (Strto);            MailMessage _mailmessage = new MailMessage (_from, _to); _mailmessage.subject = subj;//Theme _mailmessage.body = bodys;//content _mailmessage.bodyencoding = System.T Ext. encoding.default;//Body Encoding _mailmessage.isbodyhtml = true;//set to HTML format _mailmessage.priority = Mailprior ity.        normal;//priority _smtpclient.send (_mailmessage); }

Invoke Example

Strin smtpserver = "smtp.163.com"; string userName = "BruceZhang80" string pwd = "111111"; string nickname = "Bruce Zhang"; string str from= "[email protected]"; string strto= "[email protected]"; string subj= "About project Progress problem"; string bodys = "Hello! <br/>, ... "; SendMail (SmtpServer, UserName, Pwd,nickname, Strfrom, Strto, SUBJ, bodys);

  

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.