c# - 为什么我无法连接到我的服务器(连接尝试失败)
问题描述
在此处输入图像描述我使用了 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 子句:
捕捉(异常前){
//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();
解决方案
确保您的桌面上没有防火墙阻止您连接到服务器。还要确保服务器没有防火墙阻止 smtp 服务正在运行的任何端口上的传入连接(25?465?587?)
推荐阅读
- lua - 为什么我的 Vector2:new(ax, ay) 函数获取的是表格而不是 num 值?
- amazon-web-services - Cognito 会自动注册联合用户吗?
- android-studio - 无法在 Android Studio 3.4.2 中创建应用资源文件
- react-native - React Native:无法将图像垂直对齐到屏幕底部
- polymer-3.x - 在子组件中传播值
- angular - Angular 7 Http Service GET 与正文
- java - 如何使用 Google 登录来授权 Youtube Data api 请求?
- python - 如何让 GAMS 的求解器从 Pyomo 工作?
- amazon-web-services - 如何将 AWS 应用程序负载均衡器配置为超过 25 个 SSL 证书限制
- mysql - 如何从 mysql 查询参数中正确调用类函数?