简体   繁体   中英

C# Email sending error on Godaddy server

I have one web application which hosted on Godaddy server. I am stuck with Failure sending mail error. I place my code here

public void Mailing()
{
 MailMessage message = new MailMessage();
 try
{
    MailAddress fromAddress = new MailAddress("mailadress@server.net");
    message.From = fromAddress;
    message.To.Add("toresive@server.com");
    message.CC.Add("ccresive@server.com");

    message.Subject = "Hello client";
    message.IsBodyHtml= true;
    string body = "Hello!<br> How are you?";

    message.Body = body;

    SmtpClient smtpClient = new SmtpClient();
    smtpClient.Host = "relay-hosting.secureserver.net";
    smtpClient.Port = 465;
    smtpClient.EnableSsl = false;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = new NetworkCredential("mailadress@server.net", "Password");
   // AdvancedIntellect.Ssl.SslSocket ssl = new AdvancedIntellect.Ssl.SslSocket();
    smtpClient.Send(message);
    smtpClient.Timeout = 10000;
    }
    catch (Exception ex)
    {
        label2.Text = ex.Message;
    }
}

}

But I got error

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 68.178.232.62: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.Activat e(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 Form1.Mailing() in c:\\inetpub\\vhosts\\pay2school.net\\httpdocs\\IPTest\\Admin\\Form1.aspx.cs:line 139

I am rely fade up with this error. :( I was change my SMTP server with smtpout.secureserver.net but not work. Please help me out. Thanks in advance.

EnableSsl should be true. If you need a timeout then its property should be set before the email is sent try adjusting like this

SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "relay-hosting.secureserver.net";
smtpClient.Port = 465;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = 
          new NetworkCredential("mailadress@server.net", "Password");

...
smtpClient.Timeout = 10000;
smtpClient.Send(message);

I faced the same problem when I say my previous C# working code (that was sending emails using Godaddy server) wasn't sending emails anymore. So I spend 5 hours to find the actual problem

The problem is that Godaddy changed the settings on their servers. Due to this you won't be able to send email using:

  1. "smtpout.secureserver.net" host.
  2. local host (local system).

I solved this by doing 2 things:

  1. Used SmtpClient Host as "relay-hosting.secureserver.net".

  2. Put my web page on my Godaddy shared server (as localhost will still not able to send smtp email due to security added by Godaddy).

This is the correct working code from my side:

MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("test@yourdomain.com");
mailMessage.To.Add(new MailAddress("senderemail@gmail.com"));

mailMessage.Subject = "hello";
mailMessage.IsBodyHtml = true;
mailMessage.Body = "hello how are you";

SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("test@yourdomain.com", "yourpassword");
client.Host = "relay-hosting.secureserver.net";
client.Send(mailMessage);

In the above code see how I added the host :

client.Host = "relay-hosting.secureserver.net";

The mail will reach you in 25 to 30 seconds time. If you still can't find the email kindly check your spam folder.

Proof

At the time of writing this answer I tested my code and found the send email to my Gmail Inbox. See the below image as a proof: 在此处输入图片说明

Check the code below. You have to change client.Host = "smtpout.secureserver.net."

MailMessage msg = new MailMessage(txtemail.Text, "shopover@vibrantinfosystems.com");
msg.Subject = "Contact Us";
string body = "Name: " + txtname.Text.Trim() + "";
body += "<br />Email:" + txtemail.Text + "";
body += "<br /><br /> Subject :" + txtsubject.Text + "";
body += "<br /><br />Message : " + txtmessage.Text + "";
msg.Body = body;

msg.IsBodyHtml = true;

SmtpClient client = new SmtpClient();
client.Host = "smtpout.secureserver.net.";

client.Send(msg);
client.Timeout = 10000;
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Mail Sent Successfully!!');", true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM