The SMTP send method always throws an exception. Message: Mail sending failure
Here is my code:
MailMessage mm = new MailMessage(); mm.To.Add(" Yuvraj.dhot@xxxxx.co.in "); mm.From = new MailAddress(" Kumar.Chaudhari@xxxxx.co.in "); 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; }
I also tried using
ss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
Now he does not generate any exceptions, he carries out a fine, but the recipient does not receive mail in his inbox.
How can i fix this?
Edit is a stack trace receiving
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
source share