title: SMTP server not getting credentials from C# code
body: <p>I'm trying to set up an automatic email sender. </p>
  
  <p>My smtp server requires authentication. I'm not using ssl but still I'm getting the following response from server:</p>
  
  <blockquote>
    <p>The server response was: 5.7.1 You are not authorized, authentication is required. </p>
  </blockquote>
  
  <p>And if I check on the server it got an empty username.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void email_send(string mailadress,string docname)
  {
    string host = "myhost";
    string username = "user";
    string password = "password";
    int port = 625;
    var nc = new NetworkCredential(username, password);
    var auth = nc.GetCredential(host,port,"Basic");
    using (var mail = new MailMessage())
    using (var SmtpServer = new SmtpClient())
    {
      SmtpServer.Host = host;
      SmtpServer.Port = port;
      SmtpServer.Credentials = auth;
  
      mail.From = new MailAddress("fromadress");
      mail.To.Add(mailadress);
      mail.Subject = "Subject";
      mail.Body = "Body";
  
      Attachment attachment;
      attachment = new Attachment("D:/" + docname + ".pdf");
      mail.Attachments.Add(attachment);
      mail.IsBodyHtml = true;
  
      SmtpServer.DeliveryFormat = SmtpDeliveryFormat.International;
      SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
      SmtpServer.Send(mail);
    }
  
  }
  </code></pre>