2016-10-16 43 views
0

電子郵件在我的應用程序需要通過C#(使用Gmail或Hotmail)發送電子郵件 localhost上它的工作確定沒有錯誤,但在上傳到GoDaddy的託管所有的時間,我有錯誤,如C#錯誤使用Gmail或Hotmail

的Hotmail: 代碼:

  SmtpClient SmtpServer = new SmtpClient("smtp-mail.outlook.com"); 
 
      var mail = new MailMessage(); 
 
      mail.From = new MailAddress("[email protected]"); 
 
      mail.To.Add(ReciverMail); 
 
      mail.Subject = "Test Mail - 1"; 
 
      mail.IsBodyHtml = true; 
 
      string htmlBody; 
 
      htmlBody = "Write some HTML code here"; 
 
      mail.Body = htmlBody; 
 
      SmtpServer.Port = 587; 
 
      SmtpServer.UseDefaultCredentials = false; 
 
      SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxxx"); 
 
      SmtpServer.EnableSsl = true; 
 
      SmtpServer.Send(mail); 
 

 
      return "Mail has been successfully sent!";

錯誤: enter image description here

的Gmail: 代碼:

  MailMessage msg = new MailMessage(); 
 

 
      msg.From = new MailAddress("xxx", "xxxx"); 
 
      msg.Subject = "From ASU at " + DateTime.Now.ToString(); 
 
      msg.To.Add(ReciverMail); 
 
      msg.Body = "Test"; 
 
      msg.IsBodyHtml = true; 
 

 
      SmtpClient client = new SmtpClient(); 
 
      client.UseDefaultCredentials = false; 
 
      client.Host = "smtp.gmail.com"; 
 
      client.Port = 587; 
 
      client.EnableSsl = true; 
 
      client.DeliveryMethod = SmtpDeliveryMethod.Network; 
 
      client.Credentials = new NetworkCredential("[email protected]", "xxxxx"); 
 
      client.Timeout = 20000; 
 
      
 
      client.Send(msg); 
 
      return "Mail has been successfully sent!";

錯誤: enter image description here

回答

0

請確認您的Godaddy託管防火牆允許出站流量,並且您沒有被防病毒軟件阻止。

基本上Windows防火牆是造成這個錯誤。 SMTP試圖在端口587發佈到GMAIL和Hotmail。將端口587添加到出站規則[出站HTTP/SMTP/RDP]將解決此問題。

+0

感謝您的快速回復:),我沒有找到任何與防火牆相關的選項,如果Plesk控制面板。 –

相關問題