0

I'm trying to set up an automatic email sender.

My smtp server requires authentication. I'm not using ssl but still I'm getting the following response from server:

The server response was: 5.7.1 You are not authorized, authentication is required.

And if I check on the server it got an empty username.

Here is my 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);
  }

}
Lewis86
  • 511
  • 6
  • 15
Gego
  • 1
  • https://stackoverflow.com/questions/30342884/the-server-response-was-5-7-57-smtp-client-was-not-authenticated-to-send-anony – kooshy Dec 12 '18 at 14:11
  • 1
    Thank you for your answer, but none of the solutions worked in that thread. My problem is the smtp requires authentification, i pass it but the server not getting it – Gego Dec 13 '18 at 07:19
  • @Gego: Did u solve your problem? I also have same problem – Amir Jun 14 '19 at 22:36

0 Answers0