I have found a lot on the Internet, but I will report an error in actual application. Now I have combined my teacher's example with my own experience to summarize this method, which is actually quite simple, some predecessors have written this before, but think about it and write it on your own. Haha, don't talk about it much. Let's do it with me:
/// <Summary> /// judgment before the password is sent /// </Summary> /// <Param name = "sender"> </param> // <param name = "E"> </param> // *** 12.1am protected void btnfind_click (Object sender, eventargs e) {string loginname = "yhl"; ec_puser Ep = ec_pusermanager.getec_puserbypuserid (loginname); If (Ep! = NULL & EP. email = Email. text. trim () {sendemail (email. text. trim (), "retrieve password", "Dear user, please review your password through eshop online shopping Management Center <br/> your password is:" + EP. PWD. tostring () + "", "Sara_yhl@sina.com", "123456"); response. write ("<SCRIPT> alert ('the password has been sent to your mailbox, please check it! '); </SCRIPT> ");}}
You only need to call the following method:
/// <Summary> /// send email /// </Summary> /// <Param name = "tomail"> recipient email address </param> /// <param name = "title"> title </param> /// <Param name = "content"> email body </param> /// <Param name = "formuser"> sender account </param> /// <Param name = "userpwd"> sender password </param> Public static void sendemail (string tomail, string title, string content, string formuser, string userpwd) {mailaddress from = new mailaddress (formuser); mailaddress to = new mailaddress (tomail); mailmessage mymessage = new mailmessage (from, to); mymessage. priority = mailpriority. normal; mymessage. priority = mailpriority. normal; mymessage. isbodyhtml = false; mymessage. isbodyhtml = true; mymessage. body = content; mymessage. bodyencoding = system. text. encoding. utf8; mymessage. subject = title; string smtpserver = "smtp.sina.com"; // use the SMTP protocol sent by your server # Sina mail: Smtp.sina.com Netease Email: "smtp.126.com"; QQ Email: smtp.qq.com
Smtpclient client = new smtpclient (smtpserver); system. net. networkcredential cred = new system. net. networkcredential (formuser, userpwd); client. credentials = cred; client. send (mymessage );