我有一個解決方案,在用戶忘記密碼時檢索用戶密碼。我做了很好的代碼,但是出現了一個SMTP異常(發送錯誤)的錯誤。我該如何解決這個問題?發送電子郵件時出錯
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = Connection.GetConnection())
{
string sql = "Select Password From Registeration Where [email protected] And [email protected]";
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("[email protected]", "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;
}
}
如何發佈錯誤/異常詳細信息? – Oded 2010-08-05 07:48:38
順便提一下,我無法解析'smtp.elarabygroup.com'。該主機是否可以從您用於測試的機器上獲得?它應該讀取「mail.elarabygroup.com」而不是? – sarnold 2010-08-05 07:54:13
我在我的公司網絡上工作,並通過outlook或mail.elarabygroup.com登錄到我的電子郵件 – Myworld 2010-08-05 08:04:56