【问题标题】:Why cant I connect to my server (Connection attempt failed)为什么我无法连接到我的服务器(连接尝试失败)
【发布时间】:2018-10-27 02:05:22
【问题描述】:

enter image description here我使用 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 子句:

catch(例外) {

            //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();

【问题讨论】:

  • 哪一行抛出异常?异常的类型是什么?异常的堆栈跟踪是什么?
  • client.Connect(SmtpServer, SmtpPortNumber, /*SecureSocketOptions.Auto*/ /*SSL*/true);它在这里抛出错误,说服务器响应时间太长
  • 请更新您的帖子以说明这一点。你还没有告诉我们ex.GetTypeex.StackTrace 是什么。
  • 对不起,我很新,请查看 header@mjwills 中的链接

标签: c# smtp mailkit


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 2019-05-17
    • 2023-01-11
    • 2015-11-22
    • 1970-01-01
    • 2016-08-20
    • 2021-09-18
    相关资源
    最近更新 更多