我在下面的代碼(我堅持在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("[email protected]", "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(EndPoint remoteEP)+35 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure ,插座s4,插座s6,插座&插座,IP地址&個地址,ConnectSocketState狀態,IAsyncResult的asyncResult,的Int32超時,異常&除外)224
[引發WebException:無法連接到遠程服務器] System.Net.ServicePoint.GetConnection(PooledStream PooledStream,對象所有者,布爾異步,ip地址&地址,插座& abortSocket,插座& abortSocket6,的Int32超時)5420699 System.Net.PooledStream.Activate(對象owningObject,布爾異步,的Int32超時,GeneralAsyncDelegate的AsyncCallback)202 System.Net.PooledStream。激活(Object owningObject,GeneralAsyncDelegate asyncCallback)+21 System.Net.ConnectionPool.GetConnection(Object owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout)+332 System.Net.Mail.SmtpConnection.GetConnection(String host,Int32 port)+160 System.Net.Mail.SmtpTransport.GetConnection(字符串主機的Int32端口)+159
爲什麼這是行不通的
確實windows xp帶有某種類型的郵件服務器,我可以在本地進行測試嗎? – leora 2009-08-06 05:59:59
只需使用您的ISP服務器,即在您的郵件客戶端中配置的服務器。 – caf 2009-08-06 09:35:23