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
- public string TestMail(string path)
- {
- string sendto = "xxxx,xxxx,xxxx"
- string sendfrom = "xxxx";
- string content = "Test Mail";
- string subject = "Mail from MyDomain.com";
- string Email_Content ="This is test.Please Ignore it."
- string MailServerName = "xxxx";
- string[] ToAddress = null;
- int i = 0;
- ToAddress = sendto.Split(',');
- try
- {
- SmtpClient mailSMTPClient = new SmtpClient("xxxx");
- mailSMTPClient.Credentials = new System.Net.NetworkCredential("xxxx","xxxx");
- MailAddress mailFromAddress = new MailAddress(sendfrom);
- mailSMTPClient.UseDefaultCredentials = true;
- MailMessage mailMessage = new MailMessage();
- mailMessage.From = new MailAddress(mailFromAddress.ToString());
- for (i = 0; i <= ToAddress.Length - 1; i++)
- {
- mailMessage.To.Add(ToAddress[i].Trim());
- }
- mailMessage.To.Add(sendfrom.Trim());
- mailSMTPClient.EnableSsl = true;
- Attachment attachment = new Attachment(path);
- mailMessage.Attachments.Add(attachment);
- mailMessage.Subject = subject;
- mailMessage.Body = Email_Content;
- mailMessage.IsBodyHtml = true;
- var _with1 = mailSMTPClient;
- _with1.DeliveryMethod = SmtpDeliveryMethod.Network;
- _with1.Send(mailMessage);
- return "Success";
- }
- catch (SmtpException ex1)
- {
- string str = null;
- if (ex1.InnerException != null)
- {
- str = ex1.InnerException.ToString();
- }
- else
- {
- str = ex1.ToString();
- }
- return str;
- }
- }
Please Help Me...
Regards,
SR.