Verify that the mailbox is valid

Source: Internet
Author: User
Tags mailmessage smtpclient

1.app_data Directory new template document (catalog optional)

1 <!DOCTYPE HTML>2 <HTML>3 <Body>4     <P>Dear {{Name}}, Hello:</P>5     <P>6Welcome you to register to become the site user, in order to complete the user registration process, please click the following link to confirm that your email address is valid:<BR/>7         <ahref= "{{Auth_url}}"Target= "_blank">{{Auth_url}}</a>8     </P>9     <P>This is an automatically generated email, do not reply.</P>Ten </Body> One </HTML>

2. Replace document characters, generate and send messages

1  Public classEmail2 {3      Public voidSendauthenticateemail (stringEmailstringSalt)4     {5         stringMailbody = File.readalltext (HttpContext.Current.Server.MapPath ("~/app_data/registeremail.htm"));6Mailbody = Mailbody.replace ("{{Name}}", email);7Mailbody = Mailbody.replace ("{{Auth_url}}","url?validate="+salt);8SmtpClient SmtpServer =NewSmtpClient ("");9Smtpserver.port =587;Ten         //smtpserver.clientcertificates = new System.Net.NetworkCredential ("email", "password"); OneSmtpserver.enablessl =true; A  -MailMessage mail =NewMailMessage (); -Mail. from =NewMailAddress ("Email"); the Mail. To.add (email); -Mail. Subject ="website name + Member Registration confirmation letter"; -Mail. Body =Mailbody; -Mail. isbodyhtml =true; + smtpserver.send (mail); -     } +}

3. Click through to verify

1  PublicActionResult Authenticateemail (stringValidatestringemail)2 {3Guid id=db. Users.firstordefault (u=> UserId;4     stringSalt=db. Profiles.singleordefault (p=>p.profileid==ID). Salt;5     if(Validate = =Salt)6     {7Db. Users.find (ID). IsActive =true;8 db. SaveChanges ();9     }Ten     Else One     { Atempdata["Error"] ="Invalid verification code or you have passed validation. "; -     } -     returnRedirecttoaction ("Index","Profiles"); the}

Verify that the mailbox is valid

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.