C# 从google发送电子邮件在生产服务器上失败,但在本地主机上正常工作
以下是控制器中的代码:C# 从google发送电子邮件在生产服务器上失败,但在本地主机上正常工作,c#,asp.net,asp.net-mvc-3,C#,Asp.net,Asp.net Mvc 3,以下是控制器中的代码: [HttpPost, ValidateInput(true)] public ActionResult Contact(ContactForm model) { if (!ModelState.IsValid) { return Json("error"); } else {
[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:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机在System.Net.Sockets.Socket.DoConnection上未能响应74.125.53.108:25(EndPoint endPointSnapshot,SocketAddress SocketAddress)位于System.Net.ServicePoint.ConnectSocketInternal(布尔连接失败,套接字s4,套接字s6,套接字和套接字,IP地址和地址,ConnectSocketState状态,IAsyncResult asyncResult,Int32超时,异常和异常)---内部异常堆栈跟踪的结束---在System.Net.PooledStream.GetConnection处(PooledStream PooledStream、对象所有者、布尔异步、IPAddress&address、Socket&abortSocket、Socket&abortSocket6、Int32 timeout),在System.Net.PooledStream.Activate处(对象所有者对象、布尔异步、Int32超时、GeneralSyncDelegate异步回调)在System.Net.PooledStream.Activate(Object owningObject,GeneralAsyncDelegate asyncCallback)在System.Net.ConnectionPool.GetConnection(Object owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout)在System.Net.Mail.SmtpConnection.GetConnection(ServicePoint ServicePoint ServicePoint)在System.Net.Mail.SmtpTransport.GetConnection中(ServicePoint ServicePoint)位于System.Net.Mail.SmtpClient.GetConnection()的System.Net.Mail.SmtpClient.Send(MailMessage message)的System.Net.Mail.SmtpClient.GetConnection()上您的服务器可能已关闭,请检查防火墙设置。InnerException中是否有任何内容?您的生产服务器是否需要代理才能访问internet?从Google发送电子邮件总是一件痛苦的事。我建议使用SendGrid或Amazon SES等付费服务。它们很便宜。@hawkke我只是使用Godaddy。这只是其中之一一个客户的登录页。我正在使用godaddy。我想我必须给他们打电话。你救了我的命-这几小时后到期!非常感谢!