With C# Sending Email (Send Password to the Email): With C# Sending Email (Send Password to the Email):


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using BAL;

using System.Data;

using System.Data.Sql;

using System.Data.SqlClient;

using System.Net.Mail;

using System.Web.Mail;

using System.Net;



public partial class ForgotPassword : System.Web.UI.Page


string forgotPwd;

string email;

string pwd = “myswamimyguru”;

protected void Page_Load(object sender, EventArgs e)





protected void btnSendSms_Click(object sender, EventArgs e)


BusinessAccessLayer BAL = new BusinessAccessLayer();


DataSet datasetValues = null;

string userid = txtRetUserId.Text;


try {

//datasetValues   = BAL.RetrieveforgotPwdBAL(userid);

//forgotPwd = datasetValues.Tables[0].Rows[0][“Ppassword”].ToString();

//email = datasetValues.Tables[0].Rows[0][“EmailId”].ToString();


txtFrom.Text = “”;

txtTo.Text = email;

txtSubject.Text = “Forgot Password”;

txtMailBody.Text = “Your Password is” + forgotPwd + ” Please Login with the credentials”;


catch (Exception ex)







BAL = null;



protected void btnGetDetails_Click(object sender, EventArgs e)


System.Net.Mail.MailMessage mailMessege = new System.Net.Mail.MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtMailBody.Text);


SmtpClient SMTPServer = new SmtpClient(“”, 587);

mailMessege.IsBodyHtml = false;


NetworkCredential nCred = new NetworkCredential(txtFrom.Text, pwd);

SMTPServer.DeliveryMethod = SmtpDeliveryMethod.Network;

SMTPServer.UseDefaultCredentials = false;

SMTPServer.Credentials = nCred;

SMTPServer.EnableSsl = true;

SMTPServer.Timeout = 20000000;






catch (Exception ex) {

Label1.Text = ex.ToString();





In the web.config add the following code




<smtp deliveryMethod=”SpecifiedPickupDirectory”>

<specifiedPickupDirectory pickupDirectoryLocation=”C:\mail”/>






Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s