【问题标题】:Mail not sending in mvc 3邮件未在 mvc 3 中发送
【发布时间】:2016-05-01 06:18:36
【问题描述】:

我已经发布了我的源代码,该资源名为

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

我已经通过 ref 实现了

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");
        }

电子邮件管理器

[System.Web.Services.WebMethod]
        public static void SendMessage(string Position, string txtname, string fromEmail)
        {
            const string SERVER = "relay-hosting.secureserver.net";
            const string TOEMAIL = "acb@gmail.com";
            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);
        }
    }

【问题讨论】:

  • connected host has failed to respond 68.178.232.62:25 错误很明显,无法建立网络连接。端口开放了吗?
  • 对不起,我是 mvc 的新手.. 你能告诉我如何检查端口是否打开.. @Raptor
  • 它与代码相关。请使用telnet 诊断网络连接。搜索谷歌。
  • 您是否配置了SmtpClient的凭据和端口。
  • 不,需要为 SmtpClient 配置凭据! @MahbuburRahman

标签: asp.net-mvc-3 email


【解决方案1】:

您似乎没有为 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);

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 2012-01-25
    • 2012-03-26
    • 2012-04-20
    • 2014-03-06
    相关资源
    最近更新 更多