Click here to Skip to main content
12,455,442 members (58,164 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
i have developed an web application to send an email to the user but every time i use it on my development server it works fine but when i deploy it on the webserver it gives an exception saying the following:

Error Message thrown from server:
Exception caught in CreateTestMessage2():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 172.16.9.99:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 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(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) 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 Default3.Page_Load(Object sender, EventArgs e) in c:\Inetpub\VSDC_App\Default3.aspx.cs:line 32


and my code is as below:


public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
        
        string to = "abcfrom@xyzfrom.in";
        string from = "abcto@xyzto.in";
        MailMessage message = new MailMessage(from, to);
        message.Subject = "Using the new SMTP client.";
        message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
        SmtpClient client = new SmtpClient("smtp.server.com");
        client.EnableSsl = false;   
        client.UseDefaultCredentials = true;
 
        try
        {
            client.Send(message);
        }
        catch (Exception ex)
        {
            Response.Write("Exception caught in CreateTestMessage2():" + ex.ToString());
        }
 
    }
}
will anyone help me out what is the problem.
thank for reply/replies in advance.
Posted 11-Mar-12 0:02am
Updated 11-Mar-12 0:06am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The message is perfectly clear, the machine at IP address 172.16.9.99 will not accept an SMTP request on port 25. You need to contact the owners of the server to try and find out why.
  Permalink  
Comments
Espen Harlinn 7-May-12 6:13am
   
5'ed!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi,

See this link if could help...

Send email with attachment

Please do not forget to vote if could help so that others may consider as an answer.

Regards,
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 13

Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>
If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
Tutorials on sending Email in ASP.NET[^]
  Permalink  
Comments
Espen Harlinn 7-May-12 6:13am
   
Good point, nice links :-D
Sandeep Mewara 7-May-12 6:40am
   
Thanks.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Please refer following url,

Send mail using Google Apps[^]

Hope this may help you...
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

Try this code....

email-sending-in-aspnet[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 11

try this

MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
           MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
           MailMessage newmsg = new MailMessage ( mailfrom, mailto );
 
           newmsg.Subject = "Subject of Email";
           newmsg.Body = "Body(message) of email";
 
           ////For File Attachment, more file can also be attached

           Attachment att = new Attachment ( "G:\\code.txt" );
           newmsg.Attachments.Add ( att );
 
           SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
           smtps.UseDefaultCredentials = false;
           smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" );
           smtps.EnableSsl = true;
           smtps.Send ( newmsg );
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 14

I got same error, in web.config file I changed the IIS server name to our exchange server name, it worked lovely.

Hassan Shaqhan
  Permalink  
Comments
Abhishek Pant 16-Jul-15 7:13am
   
Code Project Quick Answers FAQ[^]
See third last point. this not not a way out to post answers for the 3 years old post.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 16 Jul 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100