Hello! I have some problem with smtp
when I try to use a variable as the mail receiver of the email, it doesn’t work. But if I write the mail receiver in the code myself - it works
This is my code:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.mail.ru");
SmtpServer.Timeout = 100;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Port = 587;
mail.To.Add(new MailAddress(mailReceiver));
mail.Subject = "New feedback!";
mail.Body = $"Thanks for your feedback!";
SmtpServer.Credentials = new System.Net.NetworkCredential("hided mail", "hided password") as ICredentialsByHost; SmtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpServer.Send(mail);