hii everyone...
i want code for sending mails from database using c# for forgot password...
actually what i need is to send a mail to the user when enters his email id
if that id is existing in the database then the password of the user will be sent to the email id specified........
can any one give code for this.......
Loading
Niradhip ChakrabortyPosted Sep 9, 2008, 3:32 AM
The following code I have used to send mail when user forget his password.I asked user for his email address followed by
a security question and answer. If everything match an email will shoot to user. In my case the password is encrypted in database
so I have used a dll to decrypt it. 'objEncrypt' is the instance of that dll class. I also have used another dll class clsDBComponent
and create an instance 'objDataAccess'. You can avoid this two part and use normal ado.net method to check the data provided by the
user in database. I have used VS2005. Don’t forget to specify the namespace->using System.Net.Mail and configure smtp mail server in web.config to send mails.
protected void btnSend_Click(object sender, EventArgs e)
{
string strConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
clsDBComponent objDataAccess = new clsDBComponent();
string strConfHTML = "";
try
{
objDataAccess.ConnectionString = strConnectionString;
clsPwdCrypto objEncrypt = new clsPwdCrypto();
string strSQL = "select * from Vendors where ven_txt_EmailAddr='" + txtFPname.Text + "'and ven_seq_QuestionID = '" + cboSecurityQuestion.SelectedValue + "'and ven_txt_Answer = '" + txtanswer.Text + "' ";
DataSet dstData = new DataSet();
string strPassword = null;
string strExhibitorName = null;
objDataAccess.GetDataSet(ref dstData, strSQL, "Event");
for (int intIndex = 0; intIndex < dstData.Tables["Event"].Rows.Count; intIndex++)
{
strPassword = objEncrypt.dCrypt(dstData.Tables["Event"].Rows[intIndex]["ven_txt_Password"]).ToString();
strExhibitorName = dstData.Tables["Event"].Rows[intIndex]["ven_txt_VendorName"].ToString();
Session["CompanyName"] = "ABC";
strConfHTML = strConfHTML + "
strConfHTML = strConfHTML + "
strConfHTML = strConfHTML + "
strConfHTML = strConfHTML + "
strConfHTML = strConfHTML + " Dear " + strExhibitorName + ",
"; strConfHTML = strConfHTML + " The LogIn Details are as Follows:
";
strConfHTML = strConfHTML + " UserName: " + txtFPname.Text + ",
";
strConfHTML = strConfHTML + " Password: " + strPassword + "
";
strConfHTML = strConfHTML + "
strConfHTML = strConfHTML + "
strConfHTML = strConfHTML + "
strConfHTML = strConfHTML + "";
strConfHTML = strConfHTML + "";
string strFrom = null;
strFrom = [email protected];
MailMessage mlMsgclient = new MailMessage(strFrom, txtFPname.Text);
mlMsgclient.Subject = "Registration confirmation";
mlMsgclient.Body = strConfHTML;
mlMsgclient.IsBodyHtml = true;
SmtpClient emailtoClient = new SmtpClient();
emailtoClient.Send(mlMsgclient);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
objDataAccess = null;
}
}