当tyr发送电子邮件时出错 [英] a have a error when tyr send email

查看:134
本文介绍了当tyr发送电子邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送电子邮件时出错

 SqlConnection scon_forgott = 
new SqlConnection( ConfigurationManager.ConnectionStrings [ MyConnectionString]。ToString());



scon_forgott.Open();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter( select *来自tbl_Users,其中Email =' + a.Text + '
scon_forgott);

da.Fill(dt);

if (dt.Rows.Count > 0
{
string newpass = Guid.NewGuid()。ToString();
string hashPass = FormsAuthentication.HashPasswordForStoringInConfigFile(newpass, MD5);
Classes.Users clsUsers = new Classes.Users();
DataSet ds = clsUsers.SelectRow_User(dt.Rows [ 0 ] [ 用户名]的ToString());
DataRow drRow = ds.Tables [ tbl_Users]。行[ 0 ];
clsUsers.updatePasswordNew( int .Parse(drRow [ ID]。ToString()),hashPass);
MailMessage mail = new MailMessage();
mail.From = new MailAddress( email@mydomains.com);
mail.To.Add( new MailAddress(drRow [ 电子邮件]的ToString()))。
mail.Subject = subjectttttt;
mail.Body = booooooooodddddyyyyyyyyy;
mail.IsBodyHtml = true ;
SmtpClient smtp = new SmtpClient( smpt .mydomains.com);
smtp.Credentials = new NetworkCredential( email@mydomains.com bIXSg1a8);
smtp.EnableSsl = false ;
smtp.Send(mail);
Label lbl = LoginView1.FindControl( lblError as 标签;
lbl.ForeColor = Color.ForestGreen;
lbl.Text = 发送新通行证;
}
else
{
Label lbl = LoginView1.FindControl( lblError as 标签;
lbl.ForeColor = Color.Red;
lbl.Text = 找不到用户;
}





和我的错误

连接尝试失败,因为已连接派对在一段时间后没有正确回复,或者建立连接失败,因为连接主机...

如何解决它。

解决方案

该错误似乎与您的SMTP设置有关。您的SMTP服务器无法访问 - IP地址,用户名或密码错误。



另外SMTP客户端的端口应该是 25 (默认值),但你应该查看你的SMTP关于它的服务器。



你也可以尝试将 smtp.Timeout 的值增加到更高的值。


将EnableSsl更改为True,你需要smtp.Port属性.....什么是SMTP端口???



这样as:Gmail端口是587





 SmtpClient客户端=  new  SmtpClient(); 
client.Host = smtp.gmail.com;
client.EnableSsl = true ;
client.Credentials = new NetworkCredential( faaaadi.halboni585@gmail.com 您的密码);
// client.UseDefaultCredentials = False
client.Port = 587 ;
// client.Timeout = 20000
client.Send(msg);


i have a error when send email

SqlConnection scon_forgott =
                           new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString());



                       scon_forgott.Open();
                       DataTable dt = new DataTable();
                       SqlDataAdapter da = new SqlDataAdapter("select * from tbl_Users where Email='" + a.Text + "'",
                           scon_forgott);

                       da.Fill(dt);

                       if (dt.Rows.Count > 0)
                       {
                           string newpass = Guid.NewGuid().ToString();
                           string hashPass = FormsAuthentication.HashPasswordForStoringInConfigFile(newpass, "MD5");
                           Classes.Users clsUsers = new Classes.Users();
                           DataSet ds = clsUsers.SelectRow_User(dt.Rows[0]["UserName"].ToString());
                           DataRow drRow = ds.Tables["tbl_Users"].Rows[0];
                           clsUsers.updatePasswordNew(int.Parse(drRow["ID"].ToString()), hashPass);
                           MailMessage mail = new MailMessage();
                           mail.From = new MailAddress("email@mydomains.com");
                           mail.To.Add(new MailAddress(drRow["Email"].ToString()));
                           mail.Subject = "subjectttttt";
                           mail.Body ="booooooooodddddyyyyyyyyy";
                           mail.IsBodyHtml = true;
                           SmtpClient smtp = new SmtpClient("smpt.mydomains.com");
                           smtp.Credentials = new NetworkCredential("email@mydomains.com", "bIXSg1a8");
                           smtp.EnableSsl = false;
                           smtp.Send(mail);
                           Label lbl = LoginView1.FindControl("lblError") as Label;
                           lbl.ForeColor = Color.ForestGreen;
                           lbl.Text ="send new pass";
                       }
                       else
                       {
                           Label lbl = LoginView1.FindControl("lblError") as Label;
                           lbl.ForeColor = Color.Red;
                           lbl.Text = "user not found";
                       }



and my error
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host ...
how to resolve it.

解决方案

The error seems to be related to your SMTP settings.Your SMTP server is not accessible - wrong IP address, username or password.

Also the port for SMTP client should be 25 (the default value) but you should check on your SMTP server about it.

You could also try to increase the value of smtp.Timeout to a higher value.


change EnableSsl to True, and you need the smtp.Port property..... what is the SMTP port???

such as: Gmail port is 587


SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Credentials = new NetworkCredential("faaaadi.halboni585@gmail.com", "your Password");
//client.UseDefaultCredentials = False
client.Port = 587;
//client.Timeout = 20000
client.Send(msg);


这篇关于当tyr发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆