私は以下のコードを持っています(私は本名を公開しないために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)+239System.Net.Sockets.Socket。 InternalConnect(EndPoint remoteEP)+35 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure、Socket s4、Socket s6、Socket&socket、IPAddress&address、ConnectSocketState state、IAsyncResult asyncResult、Int32 timeout、Exception&exception)+224
[WebException:リモートサーバーに接続できません] System.Net.ServicePoint.GetConnection(PooledStream PooledStream、オブジェクト所有者、ブール非同期、IPAddress&アドレス、Socket&abortSocket、Socket&abortSocket6、Int32タイムアウト)+5420699 System.Net.PooledStream.Activate(オブジェクトowningObject、ブール非同期、Int32タイムアウト、GeneralAsyncDelegate asyncCallback)+202 System.Net.PooledStream.Activate(Object owningObject、GeneralAsyncDelegate asyncCallback)+21 System.Net.ConnectionPool.GetConnection(Object owningObject、GeneralAsyncDelegate asyncCallback、Int32 CreationTimeout)+332システム.Net.Mail.SmtpConnection.GetConnection(String host、Int32 port)+160 System.Net.Mail.SmtpTransport.GetConnection(String host、Int32 port)+159
これが機能しない理由の提案