The following code sample shows how to sent lost password by mail
using System.Data.SqlClient; using System.Net.Mail; using System.Net.Mime;
protected void Button1_Click(object sender, EventArgs e) { ob.get_username = TextBox1.Text; DataSet ds = us.password_fetch(); if (ds.Tables[0].Rows.Count != 0) { Label1.Text = ds.Tables[0].Rows[0]["username"].ToString(); Label2.Text = ds.Tables[0].Rows[0]["password"].ToString(); Label3.Text = ds.Tables[0].Rows[0]["mailid"].ToString(); } try { SmtpClient smpclient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromaddress = new MailAddress("aaa@aaa.com", ""); smpclient.Host = "photo43"; smpclient.Port = 25; message.From = fromaddress; message.To.Add(TextBox2.Text); message.Subject = "Retrieve Your Password"; message.IsBodyHtml = true; ; string body = ("username=" + Label1.Text + " " + "password=" + Label2.Text + " " + "mailid=" + Label3.Text + " "); message.Body = body;
smpclient.Send(message); ScriptManager.RegisterStartupScript(this, this.GetType(), "dg", "", false); } catch (SmtpException ex) {
} } catch (Exception ex) { }
}
|
| Author: Kapil Dhawan 16 Jun 2008 | Member Level: Gold Points : 1 |
Hello, nice piece of code thanks for sharing your knowledge with us. Keep posting useful code Regards, Kapil
|