введите описание изображения здесь Я использовал mailkit и работает на 100% с outlook smtp, но не с моим собственным доменом.
using (var client = new SmtpClient())
{
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect(SmtpServer, SmtpPortNumber, /*SecureSocketOptions.Auto*/ /*SSL*/true);
// Note: only needed if the SMTP server requires authentication
// Error 5.5.1 Authentication
client.Authenticate(UsernameD, PasswordD);
client.Send(mimeMessage);
client.Disconnect(true);
}
предложение catch:
поймать (исключение ex)
{
//when any error occurrs in this method the error message is written in the log file (log.txt) which is located in the root.
using (StreamWriter writer = new StreamWriter(LogError, true))
{
writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
"" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
}
Application.ExitThread();
Application.Exit();