: Hi all,
:
: Trying to send mail with System.Net.SmtpClient, using very simple
: code
: just for testing:
: SmtpClient smtp = new SmtpClient("mail.server.com", 25);
: smtp.Credentials = new
: System.Net.NetworkCredential("user", "password");
:
: try
: {
: smtp.Send("sen...@server.com",
: "recipi...@server.com",
: "Subject",
: "Body");
:
: MessageBox.Show("Mail Sent!");
: }
: catch (Exception ex)
: {
: txtErrorMsg.Text = ex.ToString();
: }
:
: BTW, the mail.server.com is not mine, it's an ISP mail server.
:
: On my local machine, this code works fine and actualy sending the
: mail.
:
: BUT, on my remote server the same code produces the exceptions as
: follows:
:
: System.Net.Mail.SmtpException: Failure sending mail. --->
: System.Net.WebException: Unable to connect to the remote server --->
: System.Net.Sockets.SocketException:
No connection could be made
: because the target machine actively refused it
: 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)
: --- End of inner exception stack trace ---
: 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)
: --- End of inner exception stack trace ---
: at System.Net.Mail.SmtpClient.Send(MailMessage message)
: at System.Net.Mail.SmtpClient.Send(String from, String recipients,
: String subject, String body)
: at TestWindows.FrmSendSMTPMail.btnSend_Click(Object sender,
: EventArgs e)
:
: Weird stuff...
: My remote server has Windows Server 2003.
:
: So, am I missing something?
: Sounds to me like a connectivity problem... How can I check that?
:
: Thanks in advance,
: Danny
:
This line explains the error:
No connection could be made because the target machine actively refused it
It appears that either either your firewall or their firewall blocks the connection. You should check the port settings or account settings. It also helps to check if your can manually send a mail using the remote system.