title: Mail sending fails through c# when encryption connection is TLS
body: <p>I am setting up mail sending in my code as below</p>
  
  <pre><code>    NetworkCredential nc = new NetworkCredential(ConfigurationManager.AppSettings["EmailId"].ToString(), ConfigurationManager.AppSettings["Password"].ToString());
      MailMessage mm = new MailMessage();
      mm.From = new MailAddress(SendEmailaddress);
      mm.Body = "Test Mail";
      mm.IsBodyHtml = true;
      mm.BodyEncoding = System.Text.Encoding.UTF8;
      mm.To.Add(ToEmailAddress);
      mm.Subject = "Test";
      SmtpClient sp = new SmtpClient();
      sp.UseDefaultCredentials = false;
      sp.Credentials = nc;
      sp.EnableSsl = true;
      sp.DeliveryMethod = SmtpDeliveryMethod.Network;
      sp.Port = 587
      sp.Host = ConfigurationManager.AppSettings["SMTP"].ToString();
      sp.Send(mm);
  </code></pre>
  
  <p>A error is thrown at the time of mail sending. Mail sending works if I configure outlook on the same PC with these settings with TLS as encrypted connnection.
  I have checked many posts where it is suggested that EnableSsl = true should be set for TLS to work but it does not work for me. It throws below error</p>
  
  <blockquote>
    <p>Transaction failed. The server response was: 5.7.1
    : Recipient address rejected: Access denied
    at System.Net.Mail.RecipientCommand.CheckResponse(SmtpStatusCode
    statusCode, String response)    at
    System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
    MailAddressCollection recipients, String deliveryNotify,
    SmtpFailedRecipientException&amp; exception)    at
    System.Net.Mail.SmtpClient.Send(MailMessage message)</p>
  </blockquote>
  
  <p>I have hit a roadblock as no solution is found. is there a setting which needs to be done on server?</p>