Registering ——. NET code with mailbox validation

Source: Internet
Author: User
Tags mailmessage smtpclient

In writing some user-oriented website class program, the essential one is to register, usually, we will choose to register after the mailbox verification, or mobile phone to send a verification code registration. The previous article has simply described the mobile phone authentication registration, this article mainly introduces the mailbox verification.

The main steps of the mailbox verification are: The user fills in the mailbox account and submits, the background determines whether the input is the valid mailbox, if is the valid mailbox, sends the verification link to the input mailbox, the user through the mailbox link, successfully registers.

To implement this function, first, when filling in the registration information, the background generates a default state (for example: state=0, indicating not verified) into the database. After the form is submitted, the input content is stored in the database, and then via the Send command, a verification link is sent to the specified mailbox, and the user clicks on the link, which is the default state change (for example: State=1, which indicates validation passed), and the registration is successful.

The code to send the message 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;//Specifies the way e-mail is sent _smtpclient.host = smtpserver;//Specify the SMTP server if (YXShop.Common.WebUtility.isNumeric (smptport)) {int port = Convert.ToInt32 (smptpo                RT);            if (Port > 0) _smtpclient.port = port; } _smtpclient.credentials = new System.Net.NetworkCredential (USERNAME,PWD);//user name and password MailMessage _mai            Lmessage = new MailMessage (strfrom, Strto); _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. high;//Priority level           try {_smtpclient.send (_mailmessage);            return true;            } catch (Exception e) {throw e; }} private bool Sendtemail (string Strto, String subj, String bodys) {Userreg_accessor ta Rget = new Userreg_accessor (); TODO: Initialize to the appropriate value string smtpserver = "smtp.163.com"; TODO: Initialize to the appropriate value string smptport = "25"; TODO: Initialize to the appropriate value string userName = "**@163.com"; 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 to the appropriate value bool BL = Sendthemail (SmtpServer, Smptport, UserName, pwd, Strfrom, Strto, SUBJ, bodys);        return BL; }
First talk about these six parameters, Smtpsever is the mail server, if for smtp.163.com netease mailbox server, if it is QQ mailbox, then for smtp.qq.com, if it is other mailbox, you can query the network. Smptport is the port number, usually the NetEase mailbox and QQ mailbox send port port number is 25,username is the sending side account, usually send the mailbox account, and strfrom the same. PWD for the sending end of the mailbox password, Strto for the registered mailbox, that is, enter a valid mailbox account. SUBJ is the subject of the message sent, Bodys is the message body that is sent.

If all the configurations are correct, call the Send method to send the message. In the body of the message is set up, you can achieve through the mailbox registration function.

Simple summary as above, if there are errors, welcome to point out, greatly appreciated!

Registering ——. NET code with mailbox validation

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.