Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;

public partial class Login_Forgot_Password : System.Web.UI.Page
{
    public string pwd { get; set; }
    public string email { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        DbConnection.connect();
    }
    protected void Btn_R_Password_Click(object sender, EventArgs e)
    {
        Password_Check();
    }
    public void Password_Check()
    {
        try
        {
            string username = Txt_Uname.Text;
            string mobile = Txt_M_Number.Text;
            SqlCommand cmd = new SqlCommand("select Password,Email from Login where Username=@username and Mobile=@mobile", DbConnection.mCon);
            cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
            cmd.Parameters.Add("@mobile", SqlDbType.VarChar).Value = mobile;
            SqlDataAdapter madp = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            madp.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                pwd = dt.Rows[0][0].ToString();
                email = dt.Rows[0][1].ToString();

                MailMessage m = new MailMessage();
                m.To.Add(new MailAddress(email));
                m.From = new MailAddress("ravee@gmail.com");
                m.Subject = "Password Recovery";
                m.IsBodyHtml = true;
                m.Body = "Dear User,<p />Please use the following password to login.<p />Password : " + pwd +
                      "<p />WebMaster,<br />PhoneBook.Com";
                SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
                smtp.Send(m);
                Lbl_Msg.Text = "Your password was mailed to you. Please use that password and <a href="../login.aspx">login</a>";

                Txt_Uname.Text = Txt_M_Number.Text = "";
            }
            else
            {
                Lbl_Msg.Text = "Please Enter a Valid User Name & Mobile Number";
            }
        }
        catch
        {
            Lbl_Msg.Text = "Please Enter a Valid User Name & Mobile Number";
        }
    }
    protected void Btn_Cancel_Click(object sender, EventArgs e)
    {
        Txt_M_Number.Text = Txt_Uname.Text = "";
    }
}
Posted
Updated 17-Jan-13 0:12am
v2
Comments
__TR__ 17-Jan-13 6:14am    
And your question is ?
ravuravu 17-Jan-13 6:16am    
error occuring in the line smtp.send(m); and it goes to catch statement
ravuravu 17-Jan-13 6:20am    
when i use exception i got this message
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at Login_Forgot_Password.Password_Check() in c:\Users\Ravu\Desktop\Employee Daily Status\Login\Forgot Password.aspx.cs:line 49

1 solution

Please review this link it might help you out....

How to send A E-Mail From Your ASP.NET web Application...?[^]
 
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