【发布时间】:2013-09-09 05:27:06
【问题描述】:
我有一个托管在 Godaddy 服务器上的 Web 应用程序。我遇到了发送邮件失败的错误。我把我的代码放在这里
public void Mailing()
{
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("mailadress@server.net");
message.From = fromAddress;
message.To.Add("toresive@server.com");
message.CC.Add("ccresive@server.com");
message.Subject = "Hello client";
message.IsBodyHtml= true;
string body = "Hello!<br> How are you?";
message.Body = body;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "relay-hosting.secureserver.net";
smtpClient.Port = 465;
smtpClient.EnableSsl = false;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("mailadress@server.net", "Password");
// AdvancedIntellect.Ssl.SslSocket ssl = new AdvancedIntellect.Ssl.SslSocket();
smtpClient.Send(message);
smtpClient.Timeout = 10000;
}
catch (Exception ex)
{
label2.Text = ex.Message;
}
}
}
但我得到了错误
System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:连接尝试失败 因为连接方在一段时间后没有正确响应 时间,或建立连接失败,因为连接的主机有 未能在 68.178.232.62:25 回复 System.Net.Sockets.Socket.DoConnect(端点 endPointSnapshot, SocketAddress 套接字地址)在 System.Net.ServicePoint.ConnectSocketInternal(布尔连接失败, Socket s4, Socket s6, Socket&socket, IPAddress&地址, ConnectSocketState 状态、IAsyncResult asyncResult、Int32 超时、 异常和异常)---内部异常堆栈跟踪结束---在 System.Net.ServicePoint.GetConnection(池化流池化流, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6,Int32 超时)在 System.Net.PooledStream.Activate(对象拥有对象,布尔异步, Int32 超时,GeneralAsyncDelegate asyncCallback) 在 System.Net.PooledStream.Activate(对象拥有对象, GeneralAsyncDelegate asyncCallback) 在 System.Net.ConnectionPool.GetConnection(对象拥有对象, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) 在 System.Net.Mail.SmtpConnection.GetConnection(服务点 服务点)在 System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) 在 System.Net.Mail.SmtpClient.GetConnection() 在 System.Net.Mail.SmtpClient.Send(MailMessage message) --- 内部结束 异常堆栈跟踪 --- 在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)在 Form1.Mailing() 在 c:\inetpub\vhosts\pay2school.net\httpdocs\IPTest\Admin\Form1.aspx.cs:line 139
我很依赖这个错误。 :( 我正在使用 smtpout.secureserver.net 更改我的 SMTP 服务器,但无法正常工作。 请帮帮我。提前致谢。
【问题讨论】:
-
通常 smtp 在端口 25 上并且该端口是打开的。你确定465是正确的吗?它似乎不可用。你能
telnet relay-hosting.secureserver.net 465验证连接吗? -
嗨!是的 Godaddy 给了我这个端口。但在此之前,我已经使用了 25、3535、80 个端口。但是这些所有端口都发送相同的错误。
-
我可以访问该服务器上的 25 端口,但不能访问 465 端口。
-
嗨!谢谢你的答复。我也使用端口 25 现在错误是变化。 System.Net.Mail.SmtpException:服务器不支持安全连接。在 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 消息)在 Form1.Mailing() 处。
-
端口 465 通常用于 SSL(所以
smtpClient.EnableSsl应该是true)...对于端口 25 它应该是false
标签: c#