0

The following code is mine and works in my machine (Windows 7):

var fromAddress = "pxx@company.com";
var toAddress = "pyyyj@company.com";
const string fromPassword = "dfdfdf";
string subject = "Test Mail Please ignore";
string body = "Test";
body += "Email: ";
body += "Subject: ";
body += "Question:";
var smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "QAsmtp.company.net";
smtp.Port = 25;
//'smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("csweb123lab", fromPassword);
smtp.Timeout = 300000;
smtp.Send(fromAddress, toAddress, subject, body);

I copied this code and run into my remote machine Windows 2008 R2 SP1 (64bit) that is also in the company network.

I am getting the below error message :

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

I pinged SMTP host response from this machine and its responding properly. I don't understand why I get this error frequently.

Nate B.
  • 942
  • 11
  • 31
user3442289
  • 53
  • 3
  • 13
  • Team , anyone can help me to resolve this issue. its working in my machine. if i run the same code in remote machine. I am getting timeout error sometime i am getting unable to connnect server. – user3442289 Mar 18 '15 at 22:17
  • See this post: http://stackoverflow.com/questions/22687211/system-net-mail-smtpexception-failure-sending-mail-from-remote-mail-server – Dermot Blair Mar 18 '15 at 22:49

1 Answers1

0

Sounds like firewall to me. Even if ping works, you may have port 25 blocked. Use telnet to test if the port is open from a DOS command line like this:

telnet QAsmtp.company.net 25
John Weisz
  • 30,137
  • 13
  • 89
  • 132
Shahzad Qureshi
  • 1,776
  • 14
  • 15