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