Register code through email Verification

Source: Internet
Author: User
Tags valid email address email account mailmessage smtpclient

Register code through email Verification

When writing user-oriented website programs, registration is an essential part. Generally, we choose to register after email verification or send verification code registration via mobile phone. The previous article briefly describes mobile phone verification and registration. This article mainly introduces email verification.

The email verification procedure is as follows: the user fills in the email account and submits it, and checks whether the entered email address is a valid email address in the background. If the entered email address is a valid email address, the user sends a verification link to the entered email address through the email address link, successfully registered.

To implement this function, first, when entering the registration information, the background generates a default status (for example, state = 0, indicating that the status is not verified) to be saved to the database. After submitting the form, save the input content to the database, and then send a verification link to the specified email address using the send command. the user clicks the link to change the default status (for example, state = 1, indicates that the registration is successful.

The code for sending an email is as follows:

Protected bool sendTheMail (string smtpserver, string smptport, string userName, string pwd, string strfrom, string strto, string subj, string bodys) {SmtpClient _ smtpClient = new SmtpClient (); _ smtpClient. deliveryMethod = SmtpDeliveryMethod. network; // specify the email sending method _ smtpClient. host = smtpserver; // specify the SMTP server if (YXShop. common. webUtility. isNumeric (smptport) {int port = Convert. toInt32 (smptport); if (port> 0) _ smtpClient. port = port;} _ smtpClient. credentials = new System. net. networkCredential (userName, pwd); // userName and password MailMessage _ mailMessage = new MailMessage (strfrom, strto); _ mailMessage. subject = subj; // topic _ mailMessage. body = bodys; // content _ mailMessage. bodyEncoding = System. text. encoding. default; // body encode _ mailMessage. isBodyHtml = true; // set it to HTML format _ mailMessage. priority = MailPriority. high; // priority try {_ smtpClient. send (_ mailMessage); return true;} catch (Exception e) {throw e;} private bool SendTEmail (string strto, string subj, string bodys) {userReg_Accessor target = new userReg_Accessor (); // TODO: the initialization value is string smtpServer = ""; // TODO: initialize to the appropriate value string smptport = "25"; // TODO: Initialize to the appropriate value string userName = "** @"; // TODO: initialize to the appropriate value string pwd = "**"; // TODO: Initialize to the appropriate value string strFrom = "**. com "; // TODO: Initialize to the appropriate value strto = "**. com "; // TODO: Initialize to the appropriate value subj =" hello Miss lu "; // TODO: Initialize to the appropriate value bodys =" ---------- "; // TODO: initialize bool bl = sendTheMail (smtpServer, smptport, userName, pwd, strFrom, strto, subj, bodys); return bl ;}
Let's talk about these six parameters. smtpSever is the mail server. If it is, it indicates the Netease mail server. If it is QQ mail, it is If it is another mailbox, You can query the network. Smptport is the port number. Generally, both Netease mail and QQ mail have 25 slogans and userName is the sender account, which is usually the sender account, which is the same as strFrom. Pwd is the sender's email password, and strto is the registered email address, that is, the valid email account entered. Subj is the subject of the sent email, and bodys is the body of the sent email.

If all configurations are correct, call the send method to send an email. Set the email body to enable email registration.

I would like to sum up the above. If you have any mistakes, please point them out. Thank you very much!

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: 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.