Click here to Skip to main content
Rate this: bad
good
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
Edited 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 at 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 at 7-May-12 6:13am
   
Good point, nice links :-D
Sandeep Mewara at 7-May-12 6:40am
   
Thanks.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

Again facing the same problem to send mail
 
System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) 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 Email_SendMail.Page_Load(Object sender, EventArgs e) in c:\Inetpub\VSDC_App\Email\SendMail.aspx.cs:line 30
 

please anyone help me
 

code:
protected void Page_Load(object sender, EventArgs e)
{

string to = "amrutbidri@gmail.com";
string from = "info@vsdcmail.in";
MailMessage message = new MailMessage(from, to);
message.To.Add("rohant@vgmail.in");
message.Subject = "Using the new SMTP client.";
message.Body = @"This mail is from server.Happy its executed. Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient("172.21.7.188");
client.EnableSsl = false;
client.UseDefaultCredentials = true;

try
{
client.Send(message);
Response.Write("Success #1");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}

}
  Permalink  
Comments
Sandeep Mewara at 7-May-12 4:24am
   
This is not an answer. Still a question.
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  

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

  Print Answers RSS
0 OriginalGriff 254
1 Nirav Prabtani 223
2 Sergey Alexandrovich Kryukov 209
3 _Amy 165
4 Richard MacCutchan 135
0 OriginalGriff 7,799
1 Sergey Alexandrovich Kryukov 6,966
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 7 May 2012
Copyright © CodeProject, 1999-2014
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