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.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
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.
Best Answer
EnableSsl
should be true. If you need a timeout then its property should be set before the email is sent try adjusting like this