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 ("smtp.163.com");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=>u.email==email). 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