title: Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail
body: <p>I am trying to send in asp.net ,so i have a function as you can see here : </p>
  
  <pre><code>public void SendEmail(string subject, string messageBody, string toAddress)
          {
              bool ssl = false;
  
              Repository.EmailConfRepository emailConf=new EmailConfRepository();
              DomainClass.EmailConfiguration e = emailConf.GetAll().First();
              if (e.EnableSsl == "true") ssl = true;
              MailMessage mail = new MailMessage();
              mail.To.Add(toAddress);
              mail.From = new MailAddress(e.EmailFrom);
              mail.Subject = subject;
              string Body = messageBody;
              mail.Body = Body;
              mail.IsBodyHtml = true;
              SmtpClient smtp = new SmtpClient();
              smtp.UseDefaultCredentials = false;
              smtp.Host = e.SmtpServer;
              smtp.Credentials = new System.Net.NetworkCredential
                  (e.Username, e.Password);
  
              smtp.Port = int.Parse(e.SmtpPort);
              smtp.EnableSsl = ssl;
              smtp.Send(mail);
          }
  </code></pre>
  
  <p>When i call this function i got this error :</p>
  
  <pre><code>Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
  </code></pre>
  
  <p>Exception details :</p>
  
  <pre><code>Exception Details: System.Net.Mail.SmtpException: Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server
  </code></pre>