Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:


C#
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
Updated 11-Mar-12 0:06am
v2

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.
 
Share this answer
 
Comments
Espen Harlinn 7-May-12 6:13am    
5'ed!
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,
 
Share this answer
 
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[^]
 
Share this answer
 
Comments
Espen Harlinn 7-May-12 6:13am    
Good point, nice links :-D
Sandeep Mewara 7-May-12 6:40am    
Thanks.
 
Share this answer
 
Please refer following url,

Send mail using Google Apps[^]

Hope this may help you...
 
Share this answer
 
Try this code....

email-sending-in-aspnet[^]
 
Share this answer
 
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 );
 
Share this answer
 
I got same error, in web.config file I changed the IIS server name to our exchange server name, it worked lovely.

Hassan Shaqhan
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900