Smtp异常需要完美的答案

时间:2018-10-01 11:47:49

标签: smtpclient

我有几个月前运行良好的这段代码。现在它抛出两个异常。

连接尝试失败,因为一段时间后连接方未正确响应,或者连接建立失败,因为连接的主机未能响应199.168.188.194:25

  1. System.Net.Mail.SmtpException:'发送邮件失败'-WebException:无法连接到远程服务器

  2. SocketException:连接尝试失败,因为一段时间后连接方未正确响应,或者由于连接的主机未能响应,建立的连接失败。

    MailMessage email_msg = new MailMessage("test@email.com", "test@email.com", "Order Confirm", "Dear ss! your Order Has Been Confirmed. Thanx For Shoping");
    email_msg.IsBodyHtml = true;
    SmtpClient mailclient = new SmtpClient();
    System.Net.NetworkCredential basic = new System.Net.NetworkCredential("username", "password");
    mailclient.Host = "mail.testdeva.com";
    mailclient.UseDefaultCredentials = false;
    mailclient.Credentials = basic;
    mailclient.DeliveryMethod = SmtpDeliveryMethod.Network;
    mailclient.Send(email_msg);
    
    email_msg.Dispose();
    email_msg = null;
    mailclient.Dispose();
    mailclient = null;
    

真的很感谢答案

0 个答案:

没有答案