Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im getting this error on trying to send mail using SMTP with gmail.
The email cannot be sent  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 74.125.127.108:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) 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(String 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) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at WebApplication3.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Noah Soft\My Documents\Visual Studio 2008\Projects\WebApplication3\WebApplication3\WebForm1.aspx.cs:line 42 

CAN ANY1 HELP THIS
Posted
Updated 10-Jan-12 23:45pm
v2
Comments
Selva K 11-Jan-12 5:40am    
Use <pre> tags...

SmtpClient client = new SmtpClient();
      client.DeliveryMethod = SmtpDeliveryMethod.Network;
      client.EnableSsl = true;
      client.Host = "smtp.gmail.com";
      client.Port = 587;

      // setup Smtp authentication
      System.Net.NetworkCredential credentials =
          new System.Net.NetworkCredential("gmailusername@gmail.com", "gmailpassword");
      client.UseDefaultCredentials = false;
      client.Credentials = credentials;

      MailMessage msg = new MailMessage();
      msg.From = new MailAddress("gmailusername@gmail.com");
      msg.To.Add(new MailAddress("xyz@gmail.com"));
      msg.Subject = "This is a test Email subject";
      msg.IsBodyHtml = true;
      msg.Body = string.Format("<html><head></head><body>Test HTML Email</body>");
      try
      {
          client.Send(msg);
          //lblMsg.Text = "Your message has been successfully sent.";
      }

      catch (Exception ex)
      {
          //lblMsg.ForeColor = Color.Red;
          //lblMsg.Text = "Error occured while sending your message." + ex.Message;

      }
 
Share this answer
 

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