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

Error When Sending Email Using c#

India777
P: 61
Hai all,
I got the Following Error When Sending Email to Live Address using SMTP in c#.

Error Details:

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 192.168.7.90:25 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)

I use the Following Code For Sending

Expand|Select|Wrap|Line Numbers
  1. public string TestMail(string path)
  2. {
  3.     string sendto = "xxxx,xxxx,xxxx"
  4.     string sendfrom = "xxxx";    
  5.     string content = "Test Mail";
  6.     string subject = "Mail from MyDomain.com";    
  7.     string Email_Content ="This is test.Please Ignore it."
  8.     string MailServerName = "xxxx";            
  9.     string[] ToAddress = null;
  10.     int i = 0;           
  11.     ToAddress = sendto.Split(',');    
  12.     try
  13.     {
  14.         SmtpClient mailSMTPClient = new SmtpClient("xxxx");
  15.         mailSMTPClient.Credentials = new System.Net.NetworkCredential("xxxx","xxxx");
  16.         MailAddress mailFromAddress = new MailAddress(sendfrom);               
  17.         mailSMTPClient.UseDefaultCredentials = true;
  18.         MailMessage mailMessage = new MailMessage();
  19.         mailMessage.From = new MailAddress(mailFromAddress.ToString());
  20.         for (i = 0; i <= ToAddress.Length - 1; i++)
  21.         {
  22.             mailMessage.To.Add(ToAddress[i].Trim());
  23.         }
  24.         mailMessage.To.Add(sendfrom.Trim());
  25.  
  26.         mailSMTPClient.EnableSsl = true;
  27.         Attachment attachment = new Attachment(path);
  28.         mailMessage.Attachments.Add(attachment);
  29.         mailMessage.Subject = subject;
  30.         mailMessage.Body = Email_Content;
  31.         mailMessage.IsBodyHtml = true;
  32.         var _with1 = mailSMTPClient;
  33.         _with1.DeliveryMethod = SmtpDeliveryMethod.Network;
  34.  
  35.         _with1.Send(mailMessage);               
  36.         return "Success";
  37.  
  38.     }
  39.     catch (SmtpException ex1)
  40.     {               
  41.         string str = null;
  42.         if (ex1.InnerException != null)
  43.         {
  44.             str = ex1.InnerException.ToString();
  45.         }
  46.         else
  47.         {
  48.             str = ex1.ToString();
  49.         }        
  50.         return str;
  51.     }
  52. }
  53.  

Please Help Me...
Regards,
SR.
May 18 '12 #1
Share this Question
Share on Google+
1 Reply


India777
P: 61
Wow.....I Solved the problem. The SMTP Service on the Server was not Start. This Cause the Error.
May 18 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.