从Google发送电子邮件在生产服务器上失败,但在本地主机上工作正常

本文关键字:主机 工作 失败 Google 电子邮件 服务器 | 更新日期: 2023-09-27 18:18:43

下面是控制器中的代码:

[HttpPost, ValidateInput(true)]
        public ActionResult Contact(ContactForm model)
        {
            if (!ModelState.IsValid)
            {
                return Json("error");
            }
            else
            {
                WebMail.SmtpServer = "smtp.gmail.com";
                WebMail.UserName = //email here
                WebMail.Password = //password here
                WebMail.EnableSsl = true;
                string message = model.Name + " " + model.Telephone + " " + model.Email + " " + model.Address + " " + model.City + " " + model.ZipCode;
                try
                {
                    WebMail.Send("example@example.com", "philaslim.com/info email", message, model.Email);
                    return Json("thanks");
                }
                catch (Exception ex)
                {
                    return Json(ex.Message.ToString());
                }
            }

正如我所说,它只在生产服务器上失败。返回的异常消息是"发送邮件失败"。什么好主意吗?

编辑:InnerException:

System.Net。System.Net.Sockets.SocketException:连接尝试失败,因为被连接的一方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机在System.Net.Sockets.Socket上未能响应74.125.53.108:25。DoConnect(EndPoint endPointSnapshot, SocketAddress SocketAddress)在System.Net.ServicePoint。ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&套接字,IPAddress&地址,ConnectSocketState状态,IAsyncResult asyncResult, Int32超时,异常&——内部异常堆栈跟踪的结束——在System.Net.ServicePoint。GetConnection(PooledStream, PooledStream,对象所有者,布尔异步,IPAddress&地址,Socket&abortSocket Socket&在System.Net.PooledStream上中止socket6, Int32超时)。在System.Net.PooledStream上激活(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)。在System.Net.ConnectionPool上激活(Object owningObject, GeneralAsyncDelegate asyncCallback)。在System.Net.Mail.SmtpConnection上GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 createtimeout)。在System.Net.Mail.SmtpTransport上GetConnection(ServicePoint)。在System.Net.Mail.SmtpClient.GetConnection()发送(MailMessage消息)

从Google发送电子邮件在生产服务器上失败,但在本地主机上工作正常

您的发送SMTP端口(25,587)可能在您的服务器上关闭,检查您的防火墙设置

相关文章: