Implementation of the Mailbox activation feature in ASP. NET MVC Registration

Source: Internet
Author: User
Tags mailmessage smtpclient

    • Basic flowchart

    • The registration page is no longer written, now paste the code that sent the message
Public ActionResult sendemial () {int customerid= 1; String validatacode = System.Guid.NewGuid ().            ToString (); try {System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress ([email protected], "Wode"); Fill in the email address, and display name System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress ([email protected], "Nide"); Fill in the recipient address and name of the message//set the Send address, and receive address, the receive address can be multiple System.Net.Mail.MailMessage mail = new System.Net.                 Mail.mailmessage (); Mail.                from = from; Mail.                To.add (to); Mail.                             Subject = "Subject content";                System.Text.StringBuilder strbody = new System.Text.StringBuilder (); Strbody.append ("Click the link below to activate the account, 48 hours, or re-register the account, the link can only be used once, please activate as soon as possible!"                </br> "); Strbody.append ("<a href= ' http://localhost:3210/Order/ActivePage?customerID=" + customerid+ "&validatacode ="                + Validatacode + "' > click here </a></br>"); Mail.                Body = Strbody.tostring (); Mail. isbodyhtml = true;//Settings display HTMLS//Set up Send mail service address System.Net.Mail.SmtpClient client = new SYSTEM.N Et.                Mail.smtpclient (); Client.                Host = "smtp.163.com"; Fill in the User name and password information associated with the server address client. Credentials = new System.Net.NetworkCredential ("[Email pRotected] "," xxxxxx "); Send mail client.            Send (mail);        } catch {} return new Emptyresult (); }

Description

    1. Fill in the User name and password information associated with the server address client. Credentials = new System.Net.NetworkCredential ("[email protected]", "xxxxxx");
      This needs to fill out the sender's mailbox name and password
    2. The contents of the message sent here will not show the linked address information, only in the way of hyperlinks, the effect:

3. Verification code is valid in two cases: 1. Verify that the link is activated within the specified time period, 2. Verify that the code is the same as the one saved in the database

    • Implementation ideas:
    1. Page requires three pages: 1. Registration page; 2. Activate page; 3. Failed page.
    2. Add an Active Status field to the database table-1 or 1 (-1 is inactive, 1 inactive), add a CAPTCHA field Validatecode, and finally add a registration Time field registereddate
    3. program, the registration page to add registration information, randomly generated registration code (GUID) added to the database, the user ID and verification code as a parameter sent to the mailbox
    4. Because ASP. NET MVC does not need to write code to get the parameters in the URL, the parameters in the action as long as the corresponding in the URL, the action will help us to automatically get the parameter information in the URL
    5. Query the database with parameter information in action to determine if registration information can be activated

Implementation of the Mailbox activation feature in ASP. NET MVC Registration

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.