我在http://SomeDomain.com上有一个网站.当我从任何计算机访问该域时,我都可以访问该网站.然后,如果我从托管该网站的服务器转到相同的域,则将无法访问该网站.好像防火墙不会启用该连接.
我知道我可以从该服务器中访问http:// localhost以便访问该网站.
无论如何,问题是我无法从该服务器发送电子邮件,我具有以下代码来发送电子邮件:
public static void SendEmail(string toEmailAddress, string subject, string body)
{
var fromAddress = new MailAddress("sales@domainName.com", "domainName");
var toAddress = new MailAddress(toEmailAddress);
string fromPassword = "MY_PASSWORD";
var smtp = new SmtpClient
{
Host = "mail.toglcloud.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("v040\sales.domainName", fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
smtp.Send(message);
}
}
当我从任何计算机上运行该代码(我已经尝试过5种不同的代码)时,它都能工作!但是,如果我在服务器(计算机托管网站,并且包含邮件服务器)上运行该确切代码,它将无法正常工作.我得到以下异常:
System.Net.Mail.SmtpException: Failure sending mail. —>
System.Net.WebException: Unable to connect to the remote server —>
System.Net.Sockets.SocketException: A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has
failed to respond 206.155.112.15:587 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) — End of inner exception stack trace —
我认为这与为什么找不到端点http://SomeDomain.com的原因相同