C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2635
Number of posts: 5623

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Failure sending mail Posted by danyadler on 1 Nov 2007 at 2:45 AM
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
Report
Re: Failure sending mail Posted by zibadian on 1 Nov 2007 at 4:11 AM
: 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.
Report
Re: Failure sending mail Posted by WEBMASTER on 2 Nov 2007 at 4:28 AM
Some ISP's including mine blocks (Port 25) and that prevents me from sending emails without going through their SMTP server.

The only option in that case is to use an alternative SMTP port and some ISP's do provide that or thrid party SMTP providers like http://www.authsmtp.com/

Also try to type "telnet mysmtpserver.com 25" on the command like to really see if you can connect at all to it. replace "mysmtpserver.com" with your own SMTP server.

But I don't know if this is a problem for you or not.

Tore Nestenius
/WEBMASTER Programmers Heaven
Report
Re: Failure sending mail Posted by danyadler on 5 Nov 2007 at 6:06 AM
: Some ISP's including mine blocks (Port 25) and that prevents me from
: sending emails without going through their SMTP server.
:
: The only option in that case is to use an alternative SMTP port and
: some ISP's do provide that or thrid party SMTP providers like
: http://www.authsmtp.com/
:
: Also try to type "telnet mysmtpserver.com 25" on the command like to
: really see if you can connect at all to it. replace
: "mysmtpserver.com" with your own SMTP server.
:
: But I don't know if this is a problem for you or not.
:
: Tore Nestenius
: /WEBMASTER Programmers Heaven

Hi there,

Okay, I've tried 2 things:
1. telneting from my pc, resulted:
telnet mail.myisp.com 25

Connecting To mail.myisp.com...
220 mxout5.myisp.com -- Server ESMTP (MSG)


2. telneting from my remote server, resulted:
telnet mail.myisp.com 25

Connecting To mail.myisp.com...
Could not open connection to the host, on port 25: Connect failed


My conclusions:
1. This is not a C# issue
2. IT IS a connectivity problem.
3. The problem might be windows' related (My pc runs on XP while the remote machine runs on Server 2003).
4. The problem is either on my remote-machine's side, OR on the ISP's side, that I don't know...

Any more conclusions?

Danny
Report
Re: Failure sending mail Posted by WEBMASTER on 16 Nov 2007 at 3:22 PM
Its your ISP, you have to use your ISP's SMTP server or some third party ones. The blocking of SMTP traffic by the ISP's is pretty common, as a way to prevent spam.


Tore Nestenius
/WEBMASTER Programmers Heaven
Report
Re: Failure sending mail Posted by marinaa on 18 Nov 2008 at 12:50 PM
: : Some ISP's including mine blocks (Port 25) and that prevents me from
: : sending emails without going through their SMTP server.
: :
: : The only option in that case is to use an alternative SMTP port and
: : some ISP's do provide that or thrid party SMTP providers like
: : http://www.authsmtp.com/
: :
: : Also try to type "telnet mysmtpserver.com 25" on the command like to
: : really see if you can connect at all to it. replace
: : "mysmtpserver.com" with your own SMTP server.
: :
: : But I don't know if this is a problem for you or not.
: :
: : Tore Nestenius
: : /WEBMASTER Programmers Heaven
:
: Hi there,
:
: Okay, I've tried 2 things:
: 1. telneting from my pc, resulted:
: telnet mail.myisp.com 25
:
: Connecting To mail.myisp.com...
: 220 mxout5.myisp.com -- Server ESMTP (MSG)
:
:
: 2. telneting from my remote server, resulted:
: telnet mail.myisp.com 25
:
: Connecting To mail.myisp.com...
: Could not open connection to the host, on port 25: Connect failed
:
:
: My conclusions:
: 1. This is not a C# issue
: 2. IT IS a connectivity problem.
: 3. The problem might be windows' related (My pc runs on XP while the
: remote machine runs on Server 2003).
: 4. The problem is either on my remote-machine's side, OR on the
: ISP's side, that I don't know...
:
: Any more conclusions?
:
: Danny
:

Hi Danny,
Use 'localhost' as the smtp server for your web application. This is the web servers smtp service and will not require any smtp authentication.

SmtpClient client = new SmtpClient("localhost");
client.Send(message);

Marina



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.