gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:10:05 26 4
gpt4 key购买 nike

Controller 中的代码如下:

[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: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败因为连接的主机未能在 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 在 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& 地址、ConnectSocketState 状态、IAsyncResult asyncResult、Int32 超时、Exception& 异常)--- 内部异常堆栈跟踪结束 --- 在 System.Net.ServicePoint.GetConnection(PooledStream PooledStream、对象所有者、 bool 异步、IPAddress 和地址、Socket 和 abortSocket , Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(对象owningObject,GeneralAsyncDelegate asyncCallback)在System.Net.ConnectionPool.GetConnection(对象owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout)在System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)在System.Net.Mail.SmtpTransport.GetConnection(ServicePoint) servicePoint) 在 System.Net.Mail.SmtpClient.GetConnection() 在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)

最佳答案

您的传出 SMTP 端口 (25,587) 可能在您的服务器上已关闭,请检查您的防火墙设置。

关于c# - 从谷歌发送电子邮件在生产服务器上失败但在本地主机上工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8611295/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com