C # send an email to retrieve the password

Source: Internet
Author: User
Tags mailmessage smtpclient

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 );

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.