我从网上找了个代码,运行的时候总是提示如下错误:
[Test mail using .net2.0] System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.5.1 Authentication Required m24sm4922832waf我的代码是这样的,大家帮着看看
static bool mailSent = false; public void SendMail()
{
//Builed The MSG
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("[email protected]");
//msg.To.Add("[email protected]");
msg.From = new MailAddress("[email protected]", "One Ghost", System.Text.Encoding.UTF8);
msg.Subject = "Test mail using .net2.0";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "This is my msg Body";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High; //Add the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("dianlongliu123", "123456789asd");
client.Port = 587;//or use 587
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 1000000;
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
object userState = msg;
try
{
//you can also call client.Send(msg)
client.SendAsync(msg, userState);
}
catch (System.Net.Mail.SmtpException ex)
{
// MessageBox.Show(ex.Message, "Send Mail Error");
TextBox1.Text = "send mail error" + ex.Message;
}
} void client_SendCompleted(object sender, AsyncCompletedEventArgs e)
{
MailMessage mail = (MailMessage)e.UserState;
string subject = mail.Subject; if (e.Cancelled)
{
string cancelled = string.Format("[{0}] Send canceled.", subject);
TextBox1.Text=cancelled ;
}
if (e.Error != null)
{
string error = String.Format("[{0}] {1}", subject, e.Error.ToString());
// MessageBox.Show(error);
TextBox1.Text = error;
}
else
{
//MessageBox.Show("Message sent.");
TextBox1.Text = "message sent";
}
mailSent = true;
} protected void Button1_Click(object sender, EventArgs e)
{
this.SendMail();
}
[Test mail using .net2.0] System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.5.1 Authentication Required m24sm4922832waf我的代码是这样的,大家帮着看看
static bool mailSent = false; public void SendMail()
{
//Builed The MSG
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("[email protected]");
//msg.To.Add("[email protected]");
msg.From = new MailAddress("[email protected]", "One Ghost", System.Text.Encoding.UTF8);
msg.Subject = "Test mail using .net2.0";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "This is my msg Body";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High; //Add the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("dianlongliu123", "123456789asd");
client.Port = 587;//or use 587
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 1000000;
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
object userState = msg;
try
{
//you can also call client.Send(msg)
client.SendAsync(msg, userState);
}
catch (System.Net.Mail.SmtpException ex)
{
// MessageBox.Show(ex.Message, "Send Mail Error");
TextBox1.Text = "send mail error" + ex.Message;
}
} void client_SendCompleted(object sender, AsyncCompletedEventArgs e)
{
MailMessage mail = (MailMessage)e.UserState;
string subject = mail.Subject; if (e.Cancelled)
{
string cancelled = string.Format("[{0}] Send canceled.", subject);
TextBox1.Text=cancelled ;
}
if (e.Error != null)
{
string error = String.Format("[{0}] {1}", subject, e.Error.ToString());
// MessageBox.Show(error);
TextBox1.Text = error;
}
else
{
//MessageBox.Show("Message sent.");
TextBox1.Text = "message sent";
}
mailSent = true;
} protected void Button1_Click(object sender, EventArgs e)
{
this.SendMail();
}
解决方案 »
- 一个aspx.cs能否访问另一个文件夹下的aspx.cx
- 想了很久还没有想出比较好的思路!sql的问题
- DropDownList控件
- location path不起作用
- 急!高分求教。用ASP.NET和C#做过DRM的朋友请指点一下!
- 用Jmail发送邮件出现这样的错误,那里大哥能帮忙一下吗?
- TreeView中TreeNode的一个属性问题
- DataGrid分页前一切正常,分页后更新、删除功能发生淆乱
- GridView控件的分页显示问题
- 虚心请教,请给理性建议,分不是问题
- 送分题!开始学习asp.net 2.0 ,从教材的示例上,遇到2个小问题。
- AspNetPager集合repeater控件分页问题,ACCESS数据库
我已经把防火墙关拉无法使用安全密码身份验证登录到服务器。 帐户: 'POP3.126.com ', 服务器: 'POP3.126.com', 协议: POP3, 服务器响应: '-ERR Not support ntlm auth method', 端口: 110, 安全(SSL): 否, 服务器错误: 0x800CCC90, 错误号: 0x800CCC18
高手帮忙呀
不要加client.EnableSsl = true;