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

5

以下是控制器中的代码:

[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());
                }

            }

正如我所说的,它只在生产服务器上失败。返回的异常信息是“无法发送邮件”。有任何想法吗?

编辑:内部异常:

System.Net.WebException:无法连接到远程服务器 ---> System.Net.Sockets.SocketException:连接尝试失败,因为连接方在一段时间后未正确响应,或者由于连接的主机没有响应而建立连接失败74.125.53.108:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,Socket s4,Socket s6,Socket& socket,IPAddress& address,ConnectSocketState state,IAsyncResult asyncResult,Int32 timeout,Exception& exception)--- 内部异常堆栈跟踪结束 ---在System.Net.ServicePoint.GetConnection(PooledStream PooledStream,Object owner,Boolean async,IPAddress& address,Socket& abortSocket,Socket& abortSocket6,Int32 timeout)在System.Net.PooledStream.Activate(Object owningObject,Boolean async,Int32 timeout,GeneralAsyncDelegate asyncCallback)at System.Net.PooledStream.Activate(Object owningObject,GeneralAsyncDelegate asyncCallback)at System.Net.ConnectionPool.GetConnection(Object owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout)at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)at System.Net.Mail.SmtpClient.GetConnection()at System.Net.Mail.SmtpClient.Send(MailMessage message)


1
内部异常中有什么信息吗? - Lester
您的生产服务器需要代理才能访问互联网吗? - hawkke
从谷歌发送电子邮件总是很麻烦。我建议选择像SendGrid或Amazon SES这样的付费服务。它们很便宜。 - Roman
@hawkke 我只是在使用Godaddy,为客户创建了一个着陆页。 - bobek
1个回答

6

您的服务器可能关闭了外发SMTP端口(25、587),请检查防火墙设置。


我正在使用Godaddy。我想我得给他们打电话。 - bobek
你救了我的命——这个任务几个小时之内就要交了!非常感谢! - bobek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接