Hello. I am writing an application on ASP.NET Core. I use MailKit to send mail. The problem is this: it is impossible to connect to the SMTP server (I did not understand the reason). Decided to use SSL. Code:
public async Task SendEmailAsync(string email, string subject, string message) { try { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Administration", "test@mail.ru")); emailMessage.To.Add(new MailboxAddress(email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.mail.ru", 25, false); await client.AuthenticateAsync("test@mail.ru", "*****"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } } catch (Exception e) { Console.WriteLine("Ошибка при отправке почты" + e.Message); } } Error: An error occurred while attempting to establish an SSL or TLS connection. SSL / TLS. The following is the case for the following reasons: I need you to verify the server's certificate. The certificate presented by the server is expired or invalid. See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate for possible solutions.
An error occurred while trying to establish an SSL or TLS connection. You may be trying to connect to a port that does not support SSL / TLS. Another possibility is that the SSL certificate presented by the server is not trusted by the system for one or more of the following reasons: The server is using a self-signed certificate that cannot be verified. The local system does not have a root or intermediate certificate required to verify the server certificate. The certificate provided by the server has expired or is invalid. See for possible solutions.
I watched the link. The solution did not help. I decided to do it as described here: Confirming Email in ASP.NET Identity
Did not help.
And what is more strange, the fact that a letter was sent a couple of times, but later ceased. Tried to specify other ports, did not help. I did not understand what was the matter.
I will be glad to hear your answers.
One possibility is that you are trying to connect to a port which does not support SSL/TLS.is there exactly to be port 25 ? - tym32167