Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am building a social networking site. The problem which i m facing is to send an email when user forgot password. Could any one help me to come out from this problem??????
Posted
Updated 23-Jan-12 19:19pm
v2
Comments
Jaganathan Bantheswaran 24-Jan-12 1:16am    
You said that i am facing problem but you didnt say about the problem that you are facing...
Prasad_Kulkarni 24-Jan-12 1:20am    
what error you are getting?
koolprasad2003 24-Jan-12 1:21am    
Please explain more
Manoj Kumar Choubey 24-Jan-12 1:22am    
explain more and give the code block

You have to add the following codes to send a mail as simple as possible...

[Example is given for gmail account.
That means you have to have one gmail account to send a mail to any address.]

string pweda = "FromMailPassword"; //(ConfigurationManager.AppSettings["password"]);
        string from = "FromYourmail@gmail.com"; //Replace this with your own correct Gmail Address
        string to = "abc@gef.com"; //Replace this with the Email Address to whom you want to send the mail
        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        mail.To.Add(to);
        mail.From = new MailAddress(from);
        mail.Subject = "This is a test mail";
        mail.SubjectEncoding = System.Text.Encoding.UTF8;
        mail.Body = "Test Mail.";

        mail.Priority = MailPriority.High;
        SmtpClient client = new SmtpClient();

        //Add the Creddentials- use your own email id and password
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential(from, pweda);
        client.Port = 587; // Gmail works on this port
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true; //Gmail works on Server Secured Layer

        try
        {
            client.Send(mail);
            Response.Write("Message Sent...");
        }
        catch (Exception ex)
        {
            Exception ex2 = ex;
            string errorMessage = string.Empty;
            while (ex2 != null)
            {
                errorMessage += ex2.ToString();
                ex2 = ex2.InnerException;
            }
            HttpContext.Current.Response.Write(errorMessage);
        } // end try


You can send from any mail address if you have any other...
Just replace with the credentials and port and host names which you can get easily get from google.

You can send anything by assigning value to 'mail.Body'.

Add this code where ever you want send the mail...

Happy coding........
 
Share this answer
 
Comments
Ok you can get the password from database for the username and just assign it to mail.Body as....

string password = getPasswordFromDatabase(userName);
mail.Body = "Your password is - " + password;

as do as directed above....
This is just a simple way of doing the task and sending a mail(fundamentals)...
You can use this and go for more complexities as per your requirements...
It not be a better idea to send password direct to mail id
use Password Recovery
Password Recovery discussion

or if you want to send directly then try
Sending mail in asp.net
 
Share this answer
 
us the Password recovery control,

Here[^]

Thanks
--RA
 
Share this answer
 

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