SMTP的發送方法始終引發異常。該消息是:發送郵件失敗發送電子郵件的問題
這裏是我的代碼:
MailMessage mm = new MailMessage();
mm.To.Add("[email protected]");
mm.From = new MailAddress("[email protected]");
mm.Subject = "Ant Subject";
mm.Body = "Body Cha MEssag here ";
SmtpClient ss = new SmtpClient("localhost");
ss.EnableSsl = false;
try
{
**ss.Send(mm);**
Result.Text = "Message Sent";
Result.ForeColor = System.Drawing.Color.Green;
}
catch (SmtpException ex)
{
Result.Text = "Message Not Sent : \n\n " + ex.Message;
Result.ForeColor = System.Drawing.Color.Red;
}
我使用
ss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
現在,它不會引發任何異常也試過,它執行罰款,但接收器在他的收件箱中沒有收到任何郵件。
我該如何解決這個問題?
編輯 - 這是堆棧跟蹤即時得到
Message=Failure sending mail. Source=System StackTrace: at System.Net.Mail.SmtpClient.Send
(MailMessage message) at WebApplication1._Default.Page_Load(Object sender, EventArgs e) in D:\Emcure-
Kumar\Work\Not in Use\WebApplication1\WebApplication1\Default.aspx.cs:line 30 InnerException:
System.Net.WebException Message=Unable to connect to the remote server Source=System StackTrace: –
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async,
IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout,
GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject,
GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject,
GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at
System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at
System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message)
InnerException: System.Net.Sockets.SocketException Message=No connection could be made because the
target machine actively refused it 127.0.0.1:25 Source=System ErrorCode=10061 NativeErrorCode=10061
發送郵件失敗 – kumar 2011-03-25 08:42:34
@他有,它是「發送郵件失敗」。 – 2011-03-25 08:43:56
您可以發佈完整的詳細信息(類型和* all *屬性,包括堆棧跟蹤和innerException類型和* all *屬性,如果它不爲null),而不僅僅是消息。 – Richard 2011-03-25 08:59:09