Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hi,

I have to validate the email addresses. For that an email containing verification link is sent to the candidates while registering. By clicking the link the database will be updated with the status of email id as verified. How can I pass the username or other details of the candidates through the verification link?

I am using asp.net with c# coding.

Have any other good methods to implement email verification? Kindly help me....

Thank you.....
Posted
Updated 2-Feb-23 0:54am
Comments
vinodkumarnie 20-Mar-13 8:34am    
Good Question..

Hi,

You can send emails by using following code

write below code in button of send verification button
C#
MailMessage mm = new MailMessage();
      mm.To.Add(new MailAddress("yourwebsitemailchecker@gmail.com", "Request for Verification"));
      mm.From = new MailAddress("yourwebsitemailid@gmail.com");
      mm.Body = "<a href="\"http://www.yourwebsitename.com/verificationpage.aspx?custid="+Session">click here to verify</a> fgdfgdfgdfgdfgdfgdfgfdg";
      mm.IsBodyHtml = true;
      mm.Subject = "Verification";
      SmtpClient smcl = new SmtpClient();
      smcl.Host = "smtp.gmail.com";
      smcl.Port = 587;
      smcl.Credentials = new NetworkCredential("yourwebsitemailid@gmail.com", "yourmailpasswrod");
      smcl.EnableSsl = true;
      smcl.Send(mm);


In the above you've to check mail checker in querystring custid

then you can check that yourwebsitemailchecker for inbox with that custid mailid
If it exists means that user verified If not follow one more send verification

I hope you understood what I said

All the Best
 
Share this answer
 
Comments
vinodkumarnie 20-Mar-13 8:35am    
nice
ADI@345 10-May-14 3:20am    
i have facing problem using this code,pls help me
Muralikrishna8811 11-May-14 14:08pm    
post your problm here , we will help you out
ADI@345 10-May-14 3:21am    
In verificationpage.aspx page contain what????
Muralikrishna8811 11-May-14 14:05pm    
verificationpage.aspx.cs contains something like this...

if(!IsPostBack){
if(Request.Querystring["custid"]!=null)
{
string customerid=Request.QueryString["custid"].toString();
//do something to very this customer using his id which is coming from querystring

}
}

If you are just looking for client side email verification[^] might be a good place for you to start.

http://www.asp.net/security/videos/implement-the-registration-verification-pattern[^] could be useful to you as well.

If you are just looking for email validation, then a simple regex pattern would be sufficient for you to validate the email on the client side - http://msdn.microsoft.com/en-us/library/ff650303.aspx[^].
 
Share this answer
 
 
Share this answer
 
v2
 
Share this answer
 
Create a link (absolute production url) of your verification page with QueryString of encrypted UserName, when the user follows the link, decrypt the QueryString inside page_load event of verification page, and verify the user details, you can also put criteria like user must validate the link within an hour or in a day. search codeproject for email sending code if required.
 
Share this answer
 
Just generate a unique token (e.g. a GUID), put that in the email, and record it against the user somewhere. When you get a hit on the verification page, check the token that's passed in the query string against the user token for the current session (or, possibly better, look for any users with that verification token and log the current session in as them), and then clear the verified status.

I can't quite remember how ASP.net stores user information but I think you can extend the default user information; this page[^] may be helpful. Alternatively, if custom membership providers look like overkill, create a new table in your database which is for pending verifications, and look up in that instead – but in that case you will have to add a validation check on logging in to check that table, or put users by default into a role called something like PendingVerification which doesn't have access to most of the site.
 
Share this answer
 
you can send a verification code to your user as below:


using System;
using System.Net;
using System.Net.Mail;

namespace EmailVerificationExample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("sender@example.com");
                message.To.Add("recipient@example.com");
                message.Subject = "Verification Email";
                message.Body = "Click this link to verify your email address: [Verification Link]";

                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.example.com";
                smtp.Port = 587;
                smtp.Credentials = new NetworkCredential("username", "password");
                smtp.EnableSsl = true;

                smtp.Send(message);
                Console.WriteLine("Verification email sent successfully!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error sending email: " + ex.Message);
            }
        }
    }
}



This code uses the MailMessage class to set the sender, recipient, subject, and body of the email, and the SmtpClient class to send the email. You will need to replace the placeholders sender@example.com, recipient@example.com, smtp.example.com, username, password, and [Verification Link] with the actual values before running this code.
 
Share this answer
 
v2
Comments
CHill60 2-Feb-23 12:07pm    
You have added nothing new to the thread - this is essentially the same code as Solution 4 posted in 2011

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900