0

I am trying to send Email through my C# code but I am getting SmtpException

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 173.194.67.109:587

Here is how I am sending Email:

string HostAddress = "smtp.gmail.com"; MailMessage msg = new MailMessage(); msg.From = new MailAddress(fromEmail); msg.Subject = "Test Email"; msg.Body = "Hi testing invoice"; msg.IsBodyHtml = true; msg.To.Add(new MailAddress("[email protected]")); SmtpClient client = new SmtpClient(); client.Host = HostAddress; client.EnableSsl = true; NetworkCredential creadit = new NetworkCredential(); creadit.UserName = msg.From.Address; creadit.Password = Password; client.UseDefaultCredentials = true; client.Credentials = creadit; client.Port = 587; client.Send(msg); 
8
  • What's the exception? Commented Jun 26, 2015 at 8:00
  • Did you have a look at SmtpException.InnerException as it could contain more detailed information. Commented Jun 26, 2015 at 8:01
  • Do you test this code behind a proxy? If so did you configure your program to use it? Maybe a firewall is blocking your request? Commented Jun 26, 2015 at 8:31
  • 1
    possible duplicate of c# SmtpClient class not able to send email using gmail Commented Jun 26, 2015 at 8:32
  • @IgnacioSolerGarcia even the solution recommended in that post doesn't work Commented Jun 26, 2015 at 8:37

1 Answer 1

1

Your problem is here:

client.UseDefaultCredentials = true; client.Credentials = creadit; 

You are specifying a set of credentials but you are also telling SmtpClient to use the default credentials (i.e. the Windows username and password of the logged-in user). Set UseDefaultCredentials to false and it will use your supplied credentials instead.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.