By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,660 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,660 IT Pros & Developers. It's quick & easy.

Failure sending mail

P: n/a
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("se****@server.com",
"re*******@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(Bool ean
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(Strin g 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?

Thanks in advance,
Danny

Oct 30 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Danny schreef:
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("se****@server.com",
"re*******@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
Is the remote server connected to the same ISP? If not, your ISP may
simply be denying connections to the mailserver other than it's own domain.
--
Rinze van Huizen
C-Services Holland b.v
Oct 30 '07 #2

P: n/a
Get the downloadable code from here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

and look at the different authentication modes.


"Danny" <ad*********@gmail.comwrote in message
news:11**********************@o38g2000hse.googlegr oups.com...
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("se****@server.com",
"re*******@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(Bool ean
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(Strin g 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?

Thanks in advance,
Danny

Oct 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.