我正在尝试通过我的网络发送电子邮件,我研究帮助没有运气。 仍然收到错误: smtpexception未被用户代码
处理 protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("abc@gmail.com");
msg.To.Add(TextBox3.Text);
msg.Subject = TextBox4.Text;
msg.Body = TextBox5.Text;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
System.Net.NetworkCredential netCred = new System.Net.NetworkCredential();
netCred.UserName = "abc@gmail.com";
netCred.Password = "11111111";
smtp.UseDefaultCredentials = true;
smtp.Credentials = netCred;
smtp.Port = 465;
smtp.EnableSsl = true;
smtp.Send(msg);
try
{
smtp.Send(msg);
Label1.Text = "Your E-Mail Sent Great Job!!!!";
}
catch (Exception ex)
{
//Handle your exception here
Label1.Text = ex.Message + " " + "Oeps, something when wrong when we tried to send the email";
return;
}
}
当我运行它时会显示此错误,突出显示smtp.Send(message);:
用户代码和发送邮件失败未对smtpException进行处理。
System.Net.Mail.SmtpException:发送邮件失败。 ---> System.IO.IOException:无法从传输连接读取数据:net_io_connectionclosed。在System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(字节[]缓冲液,的Int32偏移的Int32读,布尔的readLine)在System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader呼叫者,布尔ONELINE)在System.Net.Mail.SmtpReplyReaderFactory System.Net上System.Net.Mail.SmtpClient.GetConnection()的System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)上的System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)处的.ReadLine(SmtpReplyReader调用者) .Mail.SmtpClient.Send(MailMessage消息)---内部异常堆栈跟踪结束---在IntroAsp.net.EmailMsg.Button1_Click(对象发送者,EventArgs e)的System.Net.Mail.SmtpClient.Send(MailMessage消息) )在c:\ Users \ Regev \ Documents \ Visual Studio 2013 \ Projects \ IntroAsp.net \ IntroAsp.net \ EmailMsg.aspx.cs:第46行
答案 0 :(得分:1)
可能的解决方案:
1)制作smtpClient.UseDefaultCredentials = false;
2)凭证"用户名"和#34;密码"适用于发送电子邮件。
3)检查端口465未被防火墙阻止。
4)不使用端口号465而是使用端口587。
希望,这可能对你有帮助。
谢谢。