How to Registered Losgin Users and Send EMail At the Time.

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 1458
hi
here i post How to Registered Losgin Users and Send EMail At the Time.


protected void Bt_Submit_Click(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@UserName,@Password,@Email)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Password", txtPassword.Text);
com.Parameters.AddWithValue("@Email", txtEmail.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";


try
{

string toaddress = Email;
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("FromEmailID");
msg.To.Add(new MailAddress(toaddress));
msg.Body = "Hi";
StringBuilder mailbody = new StringBuilder();
msg.Subject = " Your Account Status " ;
mailbody.Append("Dear Sir Body Message");
msg.Body = mailbody.ToString();
msg.IsBodyHtml = true;
System.Net.NetworkCredential credential = new System.Net.NetworkCredential("YourEmailId", "pwd");
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.Credentials = credential;
smtp.Host = "HostName";
smtp.Port = PortNo;
smtp.EnableSsl = false;
smtp.Send(msg);
}
catch (Exception ex)
{
ErrorLog("Error####:" + ex.ToString());
}
}

Comments or Responses

Posted by: .Netlearner on: 3/19/2013 Level:Starter | Status: [Member] | Points: 10
What should i specify in place of hostname. [Localhost] ? am i right ot what should i specify there should i mention anything in web.config file.Whether this executes in IIS7 ?

Login to post response