title: C# email not getting sent SMTP
body: <p>I am trying to send email programmatically in C# but I don't find what I am missing. Here is the code for the same</p>
  
  <pre><code>string SendEmail(string toAddress, string subject, string body, string senderID)
          {
              string result = "Message Sent Successfully..!!";
              const string senderPassword = "mypassword";
              try
              {
                  SmtpClient smtp = new SmtpClient
                  {
                      Host = "smtp.gmail.com",
                      Port = 587,
                      EnableSsl = true,
                      DeliveryMethod = SmtpDeliveryMethod.Network,
                      Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
                      Timeout = 30000,
                  };
                  MailMessage message = new MailMessage(senderID, toAddress, subject, body);
                  smtp.Send(message);
              }
              catch (SmtpException e)
              {
                  result = "Smtp status code " + e.StatusCode;
              }
              catch (Exception ex)
              {
                  result ="Error sending email " +ex.ToString();
              }
              return result;
          } 
  </code></pre>
  
  <p>I have tried seeing the value inside result variable its has two value</p>
  
  <ol>
  <li>Smtp status code General Failure</li>
  <li>The operation has timed out// If we comment the code catch (SmtpException e) </li>
  </ol>
  
  <p>If I look in to the msdn website for SMTP status code "General failure" <a href="https://msdn.microsoft.com/en-us/library/system.net.mail.smtpstatuscode(v=vs.110).aspx" rel="nofollow">smtp status code interpretation </a> we will find that the status code means the host cannot be found and I tried doing nslookup and the host "smtp.gmail.com" is available and accessible from telnet.</p>
  
  <p>What I am missing in the program? </p>