求大神给看看

一只小小菜鸟 2013-10-01 10:35:04
发不了邮件,求大神看看哪儿有问题

protected void btbConfirm_Click(object sender, EventArgs e)
{
string str1 = "select * from yhxxb where dzyx='" + txtEmail.Text + "' and yhm='" + txtUsername.Text + "'";
if (DataBase.ExecuteRead(str1))
{
SendMessage();
}
else
{
DataBase.AlertMessagge(Page,"",GetType(),"用户名或邮箱错误!");
}
}
public void SendMessage()
{
string sqlcon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
string str1 = "select * from yhxxb where dzyx='" +txtEmail.Text + "' and yhm='" + txtUsername.Text + "'";
SqlConnection con = new SqlConnection(sqlcon);
con.Open();
SqlCommand cmd = new SqlCommand(str1, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//取数据库中的用户名和密码
string password = dr["mm"].ToString();
string username = dr["yhm"].ToString();
MailMessage mail = new MailMessage("982112101@qq.com","'" + txtEmail.Text.Trim() + "'");
mail.Subject = "找回密码";
mail.Body = "用户您好<br/>      您的用户名为:'" + username + "'<br/>      您的密码为:'" + password + "'<br/>      请妥善保管!";
mail.IsBodyHtml = true; // 是否是HTML格式
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.qq.com";//QQ的SMPT服务器IP
smtp.Port = 25;//SMPT端口号,一般为25
smtp.Credentials = new System.Net.NetworkCredential("982112101@qq.com","321"); //指定登录服务器(即邮箱的帐号和密码)的用户名和密码,注意要在自己邮箱中设置开启SMTP服务
try
{
smtp.Send(mail);
}
catch (SmtpException ex)
{
Response.Write(ex.Message);

}
dr.Close();
con.Close();
}
}

参数或变量中有语法错误。 服务器响应为: Bad address syntax
...全文
211 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
一只小小菜鸟 2013-10-02
  • 打赏
  • 举报
回复
搞定了,谢谢各位,不知怎么的就被自动判定为垃圾邮件,不予发送,搞了半天。。。。。
H_Gragon 2013-10-02
  • 打赏
  • 举报
回复
参考地址:http://blog.csdn.net/cnceohjm/article/details/9080415
protected void Button1_Click(object sender, EventArgs e)  
       {  
           string to, body, subject;  
           to = TextBox1.Text;//要发送的邮箱  
           subject = TextBox2.Text;//邮件主题  
           body = TextBox2.Text;//邮件内容  
           try  
           {  
               int nContain = 0;  
               ///添加发件人地址   
               string from = "642122542@qq.com";  
               MailMessage mailMsg = new MailMessage();  
               mailMsg.From = new MailAddress(from);  
               nContain += mailMsg.From.Address.Length;  
               ///添加收件人地址   
               mailMsg.To.Add(to);  
               nContain += mailMsg.To.ToString().Length;  
               ///添加邮件主题   
               mailMsg.Subject = subject;  
               mailMsg.SubjectEncoding = Encoding.UTF8;  
               nContain += mailMsg.Subject.Length;  
               ///添加邮件内容   
               mailMsg.Body = body;  
               mailMsg.BodyEncoding = Encoding.UTF8;  
               mailMsg.IsBodyHtml = true;  
               nContain += mailMsg.Body.Length;  
               if (mailMsg.IsBodyHtml == true)  
               {  
                   nContain += 100;  
               }  
               ///发送邮件   
               try  
               {  
                   //定义发送邮件的Client   
                   SmtpClient client = new SmtpClient();  
                   //表示以当前登录用户的默认凭据进行身份验证    
                   client.UseDefaultCredentials = true;  
                   //包含用户名和密码    
                   client.Credentials = new System.Net.NetworkCredential("642122542@qq.com", "密码");  
                   ///设置邮件服务器主机的IP地址   
                   client.Host = "smtp.QQ.com";//163的服务器是 smtp.163.com  
                   ///设置邮件服务器的端口   
                   client.Port = 25;  
                   ///配置发送邮件的属性   
                   client.DeliveryMethod = SmtpDeliveryMethod.Network;  
                   //System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strFrom, strto, strSubject, strBody);    
                   mailMsg.Priority = System.Net.Mail.MailPriority.Normal;  
                   //client.UseDefaultCredentials = false;   
                   ///发送邮件   
                   client.Send(mailMsg);  
  
               }  
               catch (Exception ex) { throw ex; }  
           }  
           catch (Exception ex) { throw ex; }  
  
  
       }  
一只小小菜鸟 2013-10-01
  • 打赏
  • 举报
回复
jan307 2013-10-01
  • 打赏
  • 举报
回复
不知道是不是@需要转义
threenewbee 2013-10-01
  • 打赏
  • 举报
回复
501 Bad address syntax 出错原因:您所填写的收件人地址格式不正确。 您可以按照以下步骤检查您填写的收件人地址: 1、请检查域名是否包含有不允许被使用的字符,如 / , * ? ; 等。这些字符有可能是您在敲击键盘时无意间输入的错误字符; 2、请检查域名格式是否合法,一般来说,域名格式为 domain.com; 3、请检查您输入的收件人地址中是否有不该出现的空格; 4、再次核对您输入的收件人地址,检查地址中是否存在一些容易混淆的字符造成您输入错。例如: 大写字母 O 与数字 0 , 小写字母 l 与数字 1 , 小写字母 g 与数字 9 , 小写字母 l 与大写字母 I 。 改善建议:经过以上检查后您还是无法找到收件人地址的错误原因,请您联系对方,确认该邮件地址是否正确。

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧