'System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated in linux

Hi i want send a mail from my linux server my code block/project is working in my local(windows) but i get this error when i run my project in linux.

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

Here is my code block where is my problem? thanks.

                string domain = "my.local";
                string userName = "info";
                string userPass = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("AkXyz2*"));
                string host = "mail.mymail.com.tr";
                string fromMail = "[email protected]";
                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                var smtp = new SmtpClient(host, 587);//port
                smtp.EnableSsl = true;
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(userName, userPass, domain);
                smtp.Credentials = credentials;
                smtp.ServicePoint.Expect100Continue = false;
                ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
                ...
                ...
                smtp.Send(mail);         


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source