I had a decision to get the user password when the user forgot the password. I did the code well, but the error appears with the exception of SMTP (sending error). How can I fix this problem?
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = Connection.GetConnection())
{
string sql = "Select Password From Registeration Where UserName=@UserName And Email=@Email";
SqlCommand com = new SqlCommand(sql, con);
com.CommandType = CommandType.Text;
com.Parameters.Add("@UserName", SqlDbType.NVarChar, 50).Value = TxtUserName.Text;
com.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = TxtEmail.Text;
SqlDataReader dr = com.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.CloseConnection);
while (dr.Read())
{
SendMail("karim-gamal@elarabygroup.com", "xxxx", TxtEmail.Text, " Hi", "Hi" + dr["Password"].ToString());
}
Response.Redirect("");
}
}
public static bool SendMail(string elarabyAccount, string password, string to, string subject, string message)
{
try
{
NetworkCredential loginInfo = new NetworkCredential(elarabyAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(elarabyAccount);
msg.To.Add(new MailAddress(to));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.elarabygroup.com", 8080);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
return true;
}
catch (Exception)
{
return false;
}
}
source
share