Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When i try to send email from my local hosting it works fin but when i try to send email from godaddy plesk hosting account it shows me error "failure sending mail"

"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 74.125.25.108: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, 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) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, 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 WebApplication1._Default.Place_Click(Object sender, EventArgs e)"

try
            {
                //Create the msg object to be sent
                MailMessage msg = new MailMessage();
                //Add your email address to the recipients
                msg.To.Add(someone@gmail.com);
                //Configure the address we are sending the mail from
                MailAddress address = new MailAddress("username@gmail.com");
                msg.From = address;
                msg.Subject = "gmail";
                msg.Body = "gmail";

                //Configure an SmtpClient to send the mail.            
                SmtpClient client = new SmtpClient();
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.EnableSsl = true;
                client.Host = "smtp.gmail.com";
                client.Port = 25;

                //Setup credentials to login to our sender email address ("UserName", "Password")
                NetworkCredential credentials = new NetworkCredential("username@gmail.com", "password");
                client.UseDefaultCredentials = true;
                client.Credentials = credentials;

                //Send the msg
                client.Send(msg);

                //Display some feedback to the user to let them know it was sent
                Label1.Text = "Your message was sent!";
            }
            catch (Exception ex)
            {
                //If the message failed at some point, let the user know
                Label1.Text = ex.ToString();
                //"Your message failed to send, please try again."
            }
Posted
Updated 9-Jan-23 19:52pm
v8
Comments
Afzaal Ahmad Zeeshan 11-Mar-15 17:17pm    
What is the message that is shown, along with "Failure sending mail"?

Also note that you should never share your username and password (even with one or two characters removed) on the internet. It's for your own privacy!
Member 10901644 12-Mar-15 12:01pm    
I have updated my Q...now can you please help me to resolve this issue. this code is also working with my godaddy classical web hosting but with plesk hosting it shows error.
Afzaal Ahmad Zeeshan 12-Mar-15 12:23pm    
I have added the answer to your problem. Please see my solution.

That is because of the port you're using and the server isn't responding to the request of yours at that port. Change the port to 25 and then retry. I have always used 25, and it always worked.
 
Share this answer
 
Comments
Member 10901644 12-Mar-15 16:14pm    
I have tried port 25, 465 and 587 all was not working and the error was same as above. Please see i have updated my Q and full error
Now i have found the solution. The code below is work for me just changing the smtp server thanks every one.

try
           {
               //Create the msg object to be sent
               MailMessage msg = new MailMessage();
               //Add your email address to the recipients
               msg.To.Add(someone@any.com);
               //Configure the address we are sending the mail from
               MailAddress address = new MailAddress("user@mydomain.com");
               msg.From = address;
               msg.Subject = "anything";
               msg.Body = "anything";

               //Configure an SmtpClient to send the mail.
               SmtpClient client = new SmtpClient();
               client.DeliveryMethod = SmtpDeliveryMethod.Network;
               client.EnableSsl = false;
               client.Host = "relay-hosting.secureserver.net";
               client.Port = 25;

               //Setup credentials to login to our sender email address ("UserName", "Password")
               NetworkCredential credentials = new NetworkCredential("user@mydomain.com", "Password");
               client.UseDefaultCredentials = true;
               client.Credentials = credentials;

               //Send the msg
               client.Send(msg);

               //Display some feedback to the user to let them know it was sent
               Label1.Text = "Your message was sent!";
           }
           catch (Exception ex)
           {
               //If the message failed at some point, let the user know
               Label1.Text = ex.ToString();
               //"Your message failed to send, please try again."
           }
 
Share this answer
 
Comments
cmodev 14-Nov-15 19:08pm    
its work fine for me, after a long time searching answers, the key is: client.Host = "relay-hosting.secureserver.net";
The solution to this is to not send email from gmail's smtp servers, send them through GoDaddy's smtp server.

http://vandelayweb.com/sending-asp-net-emails-godaddy-gmail-godaddy-hosted/[^]

A fuller explanation as to why is detailed here;

http://forums.asp.net/post/5825785.aspx[^]
 
Share this answer
 
Comments
Member 10901644 12-Mar-15 16:35pm    
I have tried this but its also not work for me. Please see I updated my Q and full errorr
You need to verify the GoDaddy SMTP settings first. Majority of the times, you will get error due to setting up an incorrect settings.

Also try to debug the code with try..catch block and track the inner exception.
 
Share this answer
 
Comments
Member 10901644 12-Mar-15 12:04pm    
How to verify GoDaddy SMTP setting in plesk hosting.
Hi
Before coding

Check if you are able to send email using the SMTP server , check the ports , in this case port 587.
Usually it's 25(SMTP) , 465(SMTP with SSL).

You can telnet

telnet <serve> <port>

You can also try to send email using telnet.
http://www.port25.com/how-to-check-an-smtp-connection-with-a-manual-telnet-session-2
 
Share this answer
 
Comments
Member 10901644 12-Mar-15 12:06pm    
port 587 is work fin with my local server and GoDaddy classical hosting. I have talk with GoDaddy support also but they have told its my script fault and their server settings are Ok.
I am receiving this error
"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 74.125.28.108:587"
 
Share this answer
 
v3
Hi,

I was also receiving error

"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 74.125.28.108:587"


Thank you again.
 
Share this answer
 
Comments
Member 10901644 21-Mar-15 13:41pm    
Code please

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