Click here to Skip to main content
15,888,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys

I'm developing a system that will send emails to supplier with a Quotations# attached to the body of the email. But just before going in deep of my assignment,
I'm currently getting this following error when i'm sending a simple email from my View Page.

C#

System.Net.Sockets.SocketException (0x80004005): 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.206.109: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)

Please Anyone Help is very welcome!!!!
It's urgent.

What I have tried:

I have tried this following:
try{
   mail.To.Add(obj.ToEmail);
                mail.From = new MailAddress("myemail@gmail.com");
                mail.Subject = obj.EmailSubject;
                mail.Body = obj.EMailBody;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 25); //I also tried 587 port but no luck
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "password");
                smtp.Send(mail);


                ViewBag.Status = "Email Sent Successfully.";
      }
      catch (Exception ex)
      {
                ViewBag.Status = ex.GetBaseException();
               // ViewBag.Status = "Problem while sending email, Please check details.";

       }
            return View();
        }
Posted
Comments
F-ES Sitecore 24-Oct-17 4:31am    
Don't send emails via gmail

Google "send email gmail c#" and you'll find thousands of articles explaining how to do this and the issues you might find such as having to configure your account to allow emails being sent programmatically.
Pacheli Dev 24-Oct-17 7:46am    
Hi F-ES
Actually I have a local smtp server that I would like to direct my emails to. Gmail way is just an example. But I will edit my question and comment to make it clear.
Thanks
F-ES Sitecore 24-Oct-17 7:48am    
It could be a network issue then where the web server can't connect to the smtp server. If you can get on the desktop of the web server you can use telnet to connect to port 25 of the smtp server and see what happens. If you can't connect via telnet then your code isn't likely to connect either.
Kornfeld Eliyahu Peter 24-Oct-17 9:31am    
Check this: https://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=2

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