一段很简单的SMTP邮件发送代码,但就是发送不成功,Gmail用FOXmail可以登录,但下面的代码确会报错:
"SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.5.1 Authentication Required. Learn more at "
环境:VS2005 WinForm
请高手帮忙
System.Net.Mail.MailMessage msg = new MailMessage();
msg.To.Add("honkang@126.com");
msg.From = new MailAddress("hkm500@gmail.com", "hkm500", Encoding.UTF8);
msg.Subject = "hello world mail";
msg.SubjectEncoding = Encoding.UTF8;
msg.Body = "hello boy,i see you here";
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("hkm500.gmail.com","********");
try
{
client.Send(msg);
MessageBox.Show("发送成功!");
}
catch (Exception ex)
{
this.richTextBox1.Text = ex.Message;
}
System.Net.NetworkCredential("hkm500.gmail.com","********"); 这个地方错了
应该是
System.Net.NetworkCredential("hkm500@gmail.com","********");