【发布时间】:2016-08-08 08:20:25
【问题描述】:
using System.Net.Mail;
protected void SendMail()
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.google.com");
SmtpServer.Timeout = 30000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.From = new MailAddress("myemail@gmail.com");
mail.To.Add("recipient@gmail.com");
mail.Subject = "test";
mail.Body = "test";
mail.Priority = MailPriority.High;
SmtpServer.Port = 587;//25
SmtpServer.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "pwd");
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Send(mail);
//MessageBox.Show("mail Send");
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message.ToString());
}
}
根据互联网上的几个来源,我没有在我的代码中发现任何错误。还是不行。
【问题讨论】:
-
最没用的说法是它不起作用 你能详细说明什么不起作用吗?有任何错误信息吗?
-
@Steve 对我来说,更没用的事情就是捕获并吞下异常。
-
如果有任何异常请告诉我们?
-
当我在 catch 块中取消注释 MessageBox 时,弹出窗口显示为“发送邮件失败”
-
并且弹出窗口不断出现。