【发布时间】:2010-11-17 06:05:19
【问题描述】:
我在下面有以下代码(我卡在xxx没有公布真实姓名)。当我上传到服务器时,这段代码可以正常工作,并且会完美地发送电子邮件。
MailMessage msg = new MailMessage();
msg.From = new MailAddress(fromEmailAddress_);
msg.To.Add(new MailAddress(toEmailAddress_));
msg.Subject = subject_;
msg.Body = body_;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("xxx@xxxx.org", "password");
try
{
SmtpClient c = new SmtpClient("mail.xxx.org");
c.UseDefaultCredentials = false;
c.Credentials = basicAuthenticationInfo;
c.Send(msg);
}
catch (Exception ex)
{
throw ex;
Console.Write(ex.Message.ToString());
}
但是当我在 Visual Studio 的机器上进行本地测试时,出现错误:
[SocketException (0x274d): 无法建立连接,因为目标机器主动拒绝了它 66.226.21.251:25] System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +239 System.Net.Sockets.Socket.InternalConnect(端点远程EP)+35 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception&异常) +224
[WebException: 无法连接到远程服务器] System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +5420699 System.Net.PooledStream.Activate(对象拥有对象,布尔异步,Int32 超时,GeneralAsyncDelegate asyncCallback)+202 System.Net.PooledStream.Activate(对象拥有对象,GeneralAsyncDelegate asyncCallback)+21 System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +332 System.Net.Mail.SmtpConnection.GetConnection(字符串主机,Int32 端口)+160 System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +159
关于为什么这不起作用的任何建议
【问题讨论】:
标签: c# asp.net email smtpclient