2016-04-29 20 views
0

我已經張貼了我的來源,已經porblem名爲郵件在MVC不發送3

連接嘗試失敗,因爲連接的方沒有正確一段時間後響應或已建立的連接失敗,因爲連接的主機沒有迴應68.178.232.62:25

我已經通過

http://developmentfaction.blogspot.in/2013/03/sending-email-with-javascript-and-aspnet.html

參考實現,請幫我解決這個問題

在此先感謝:)

查看頁面

@using (Html.BeginForm("Emailto", "Home", FormMethod.Post)) 
    { 
@Html.TextBoxFor(a => a.Position, new { @readonly = "readonly", @id = "Position", @name = "Position" }) 
    <input type="text" value="" id="txtname" name="txtname" required /> 
    <input type="email" value="" id="txtemail" name="fromEmail" required /> 
<input type="submit" id="btnApply" name="btnApply" value="Apply" /> 

控制器

[HttpPost, ValidateInput(false)] 
     public ActionResult Emailto(string Position, string txtname, string fromEmail) 

     { 
      EmailManager.SendMessage(Position, txtname, fromEmail); 
      return Redirect("Index"); 
     } 

EmailManager

[System.Web.Services.WebMethod] 
     public static void SendMessage(string Position, string txtname, string fromEmail) 
     { 
      const string SERVER = "relay-hosting.secureserver.net"; 
      const string TOEMAIL = "[email protected]"; 
      MailAddress from = new MailAddress(fromEmail); 
      MailAddress to = new MailAddress(TOEMAIL); 
      MailMessage message = new MailMessage(from, to); 

      message.Subject = "Position " + Position; 
      message.Body = "Message from: " + Position + " at " + 
          fromEmail + "\n\n" + txtname; 
      message.IsBodyHtml = false; 
      SmtpClient client = new SmtpClient(SERVER); 
      client.Send(message); 
     } 
    } 
+0

*連接的主機未能響應68.178.232.62:25*錯誤是顯而易見的,因爲網絡連接不能建立。港口是否開放? – Raptor

+0

對不起,新的mvc ..你可以請告訴我如何檢查端口是否打開.. @Raptor – Rakyir

+0

這是**沒有**相關的代碼。請使用telnet來診斷網絡連接。搜索Google。 – Raptor

回答

0

你似乎並不被提供密碼或端口爲smtp。

var loginInfo = new NetworkCredential(email, password); 
SmtpClient client = new SmtpClient(SERVER, 587); 


       client.EnableSsl = true; 
       client.UseDefaultCredentials = false; 
       client.Credentials = loginInfo; 
       client.Send(mail); 

希望這有助於