为什么我无法连接到我的服务器(连接尝试失败)

问题描述 投票:0回答:1

enter image description hereI使用mailkit并且使用outlook smtp 100%工作,但不是我自己的域。

 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子句:

catch(Exception 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();
c# smtp mailkit
1个回答
0
投票

确保桌面上没有防火墙阻止您连接到服务器。还要确保服务器没有防火墙阻止运行smtp服务的任何端口上的传入连接(25?465?587?)

© www.soinside.com 2019 - 2024. All rights reserved.