473,473 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error When Sending Email Using c#

India777
61 New Member
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
1 2950
India777
61 New Member
Wow.....I Solved the problem. The SMTP Service on the Server was not Start. This Cause the Error.
May 18 '12 #2

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

Similar topics

1
by: Lad | last post by:
I use a new webhosting provider and I can not send an email from my script. This is the script that I use to test the connection ####################### import smtplib,poplib, #I first login...
5
by: BVM | last post by:
Hi: I have a problem when sending large email(more than 20Mb) from a web page. I got timeout error. How to overcome this problem? I am thinking to have a thread to send email. Once the thread...
1
by: VB Programmer | last post by:
I am making a simple VB.NET app to send emails. I put a test button on the form with code like this: Imports System.Web.Mail : Dim msgEmail As New System.Web.Mail.MailMessage With msgEmail...
6
by: lalit26011983 | last post by:
Can any1 help me... How to send emails using asp.net.. I m using windows 2000 server and visual studio 2003(.net framework 1.1) I m not getting any error while i m sending email using...
5
by: Navin Mishra | last post by:
Hi, In load test of our .NET 2.0 socket application on Win2003 server, we are seeing sometimes WSEWOULDBLOCK error when sending data to clients. We are using synchronoous scokets with...
11
by: rote | last post by:
I'm getting the email address from an excel sheet. But i need to send the email to multiple people When printing the below i get a@a.com;b@b.com;; But i want a@a.com;b@b.com; i don't need...
0
by: trivedimca2005 | last post by:
I am using below code for sending Email using .net. Its not working on client machine. My server IP is:- 192.168.10.10 and also uses proxy and user-name and password for proxy settings are...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
6
by: Chocolade | last post by:
Hi, Im using System.Net.Mail to send email in my application it was working great without any problems untill this morning after like 20-30 tries it was sending the email ok then suddenly this...
0
by: john breaker | last post by:
Hi, Why does the following code report the error: Error! The mail could not be sent Here is the link to an actual post(try for yourself please)...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.