Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This error Comes.....
----------------------------------------------------------------

System.Net.Mail.SmtpException was caught
  Message="Failure sending mail."
  Source="System"
  StackTrace:
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at SendEmail.SendMail() in d:\AMS\Addmission_Managment_System\SendEmail.aspx.cs:line 45
  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 173.194.79.109:587"
            Source="System"
            ErrorCode=10061
            NativeErrorCode=10061
            StackTrace:
                 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
                 at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
                 at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
            InnerException:


This is Code which I Using
C#
public void SendMail()
    {
        try
        {
            MailMessage mail = new MailMessage();
            mail.To.Add("bhulku.niravvasoya@gmail.com");
            mail.From = new MailAddress("bhulku.niravvasoya@gmail.com", txtfrom.Text);
            mail.Subject = txtsubject.Text;
            mail.Body = txtmessage.Text;
            SmtpClient smtp = new SmtpClient("smtp.gmail.com");
            smtp.EnableSsl = true;
            smtp.Port = 587;
            System.Net.NetworkCredential yetki = new NetworkCredential("bhulku.niravvasoya@gmail.com", "123abc");
            smtp.Credentials = yetki;           
            smtp.Send(mail);
            Response.Write("mailiniz başarılı bir şekilde gönderilmiştir");
        }
        catch (Exception e)
        {
            Response.Write(e.Message);
        }
    }

AND any thing write in web.config file.....?
Posted
Updated 24-Oct-12 5:42am
v4
Comments
Devendra 1988 25-Oct-12 2:26am    
provide the right password to forward mail id ...check '123abc' it is a right password

Check the following points:

1- Check that this port 587 is open on your machine

2- Check if your antivirus is blocking the connection to your port
 
Share this answer
 
Comments
Sandeep Mewara 24-Oct-12 12:05pm    
My 5!
Manas Bhardwaj 24-Oct-12 15:43pm    
thx!
Niravvasoya 25-Oct-12 0:52am    
I check it out...
Firewall and antivirus both are disabled....

and how to check 587 open or not....?
[no name] 25-Oct-12 2:22am    
Well you need to contact your ISP to make sure that port 587 is not blocked at his end. I faced same issue when i was configuring my gmail in outlook. i read this somewhere on internet and asked mi ISP to unblock the port and bingo it worked.
Hi,

Read the message in the above exception.

Message="Unable to connect to the remote server"

Message="No connection could be made because the target machine actively refused it 173.194.79.109:587"

It can be either due to the following reasons

Either u may be accessing the gmail from a pc to which the gmail connection may have been terminated ie either firewall may be blocking your access to gmail. Or connection may have been timed out.

Check it out.
 
Share this answer
 
Comments
Niravvasoya 25-Oct-12 0:57am    
yes connection has been timed out when it is running...

this error also comes when i testing this program ....

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. sf4sm5136790pbc.75"
Hi,
Look at the exception message, it clearly says "No connection could be made because the target machine actively refused it 173.194.79.109:587". So try enabling inbound and outbound rules for port 587 on the server.
You can find help from this article.
http://www.windowsnetworking.com/articles_tutorials/configure-Windows-Server-2008-advanced-firewall-MMC-snap-in.html[^]
 
Share this answer
 
C#
var smtp = new System.Net.Mail.SmtpClient();
   {
       smtp.Host = "smtp.gmail.com";
       smtp.Port = 587;
       smtp.EnableSsl = true;
       smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
       smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
       smtp.Timeout = 20000;
   }
   // Passing values to smtp object
   smtp.Send(fromAddress, toAddress, subject, body);
 
Share this answer
 
Hi Niravvasoya,

Try this piece of code


C#
 System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
 message.To.Add("yourid@provider.com");
 message.Subject = "Trial Mail";
 message.From = new System.Net.Mail.MailAddress("myid@provider.com");
 message.Body = "Hi this is a trial mail"
 message.IsBodyHtml = true;

 System.Net.Mail.SmtpClient smtp = new                                  System.Net.Mail.SmtpClient("mail.provider.com"); //in case of gmail give as smtp.gmail.com
try
{
    smtp.EnableSsl = false;//try notching with true or false.
    smtp.UseDefaultCredentials = false;//try notching with true or false
    //smtp.Port = 25;
    smtp.Port = 587;//for gmail port is 25.
    System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
    NetworkCred.UserName = "myid@provider.com";
    NetworkCred.Password = "*****";
    smtp.Credentials = NetworkCred;
    smtp.Send(message);

}
catch (Exception ex)
{
    message.Dispose();
    smtp = null;

}



This works out fine for me.


Hope this works for u too..


Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900