会产生错误的代码如下
SmtpClient client
=
new
SmtpClient(
"
smtp服务器
"
);
client.Credentials = new NetworkCredential( " 用户名 " , " 密码 " );
client.UseDefaultCredentials = true ;
MailMessage mess = new MailMessage();
mess.From = new MailAddress( " 发信人地址 " , " 发信人姓名 " );
mess.To.Add( new MailAddress( " 收信人地址 " , " 收信人姓名 " ));
mess.Subject = " 主体 " ;
mess.Body = " 正文 " ;
client.Send(mess);
MessageBox.Show( " 完成 " );
client.Credentials = new NetworkCredential( " 用户名 " , " 密码 " );
client.UseDefaultCredentials = true ;
MailMessage mess = new MailMessage();
mess.From = new MailAddress( " 发信人地址 " , " 发信人姓名 " );
mess.To.Add( new MailAddress( " 收信人地址 " , " 收信人姓名 " ));
mess.Subject = " 主体 " ;
mess.Body = " 正文 " ;
client.Send(mess);
MessageBox.Show( " 完成 " );
经过研究发现产生错误的原因是设置client.UseDefaultCredentials = true;属性放在了设置client.Credentials = new NetworkCredential("用户名", "密码");的后面,只要把这两行掉换一下位置就能正常发送邮件了.