Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I Tried to send a email from gmail or hotmail, yahoo to any directionm, but didnt work...
like: http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail[^]
and there is my code for gmail:
C#
try
{

    string from = "xxx@gmail.com";
    //Replace this with your own correct Gmail Address

    string to = "yyy@gmail.com";
    //Replace this with the Email Address
    //to whom you want to send the mail

    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    mail.To.Add(to);
    mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
    mail.Subject = "This is a test mail";
    mail.SubjectEncoding = System.Text.Encoding.UTF8;
    mail.Body = "This is Email Body Text";
    mail.BodyEncoding = System.Text.Encoding.UTF8;
    mail.IsBodyHtml = true;
    mail.Priority = MailPriority.High;

    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

    //Add the Creddentials- use your own email id and password
    System.Net.NetworkCredential nt =
    new System.Net.NetworkCredential(from, "zzzzzz");

    client.Port = 587; // Gmail works on this port
    client.EnableSsl = true; //Gmail works on Server Secured Layer
    client.UseDefaultCredentials = false;
    client.Credentials = nt;
    client.Send(mail);

}
catch(Exception ex)
{
    Response.Write("Could not send the e-mail - error: " + ex.Message);
}
return View();


And error said:
Could not send the e-mail - error: Failure sending mail.

Should I add something in Web.config for configuration??

Thanks!!
Posted

The error that you're having is the error due to network issues.

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote ---> System.Net.Sockets.SocketException server: An error occurred during the connection attempt because the connected party did not properly respond after a period time or an error occurred in the connection established because connected host has failed to respond

It means, that the company is either not recieving your network request, or the company doesnot want to respond to your request. Make sure to add all the details required for the Request to be process, like Enabling SSL in the request, adding a port etc.

Going deep down into the exception, this exception is because of either the port. Try changing the port, 25 port number works for most the SMTP servers (so does for gmail, I always use that one). Also make sure the credentials are OK. If not, please fix them, if yes, then the network might be causing this problem like server down or service not available in your area sort of problem.

Comment for more information if you encounter problem again.
 
Share this answer
 
Comments
Member 10925067 7-Aug-14 22:17pm    
Hi! Thanks for respond :)
i changed the port to 25, but occur the same error...,
the error entire: http://pastie.org/9454402
Afzaal Ahmad Zeeshan 8-Aug-14 0:43am    
Well, this is a Network related this right now, if you directly go to the IP address: 74.125.29.109 you won't be able to connect. That is the error, that ASP.NET is telling you.
Member 10925067 8-Aug-14 18:25pm    
M... so what can i do for this? i need to insert some code in the part of web.config somethin like that?? Sorry... im ignorance for those things of net...
the error said:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote ---> System.Net.Sockets.SocketException server: An error occurred during the connection attempt because the connected party did not properly respond after a period time or an error occurred in the connection established because connected host has failed to respond........etc

please!! help...
 
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