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
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.....?