.NET 程序发送电子邮件仅在客户端服务器上不起作用

.NET 程序发送电子邮件仅在客户端服务器上不起作用

我最初是在 SO 中问过这个问题,但似乎这里更合适。

基本上,我有一个发送电子邮件的程序,它可以在我的本地机器和我们公司的服务器上运行。但是,当部署到客户的服务器上时,它不起作用。

由于某种原因,程序无法连接到 smtp 服务器。以下是确切的错误:

System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

当发生此错误时,我已记录 SMTP 对话并且它停留在“AUTH LOGIN”然后超时。

11/23/2021 5:00:13 PM - start to send email ...
11/23/2021 5:01:15 PM - failed to send email with the following error:
11/23/2021 5:01:15 PM - 
============================================================================
#Version: 7.8.0.1 - 2021-11-23 17:00:13:660
============================================================================
Server: smtp.gmail.com
Port: 587
ConnectType: ConnectSTARTTLS
Protocol: SMTP
AuthType: AuthAuto
UseDefaultCredentials: False
User: <Email>
Alias: 
Drafts: drafts
Password: <Password>
EHLO: False
PIPELINING: False
HeloDomain: <client.domain>
MailFrom: 
SocksProxyServer: 
SocksProxyPort: 1080
SocksProxyUser: 
SocksProxyPassword: 
ProxyProtocol: Socks5
============================================================================
[17:00:13:666:Verbose] Connecting smtp.gmail.com 587 ...
[17:00:13:774:Verbose] Connected
[17:00:14:347:S] 220 smtp.gmail.com ESMTP mu4sm722169pjb.8 - gsmtp
[17:00:14:348:C] EHLO <client.domain>
[17:00:14:566:S]
250-smtp.gmail.com at your service, [<client.ip>]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
[17:00:14:568:C] STARTTLS
[17:00:14:784:S] 220 2.0.0 Ready to start TLS
[17:00:14:898:C] EHLO <client.domain>
[17:00:15:114:S]
250-smtp.gmail.com at your service, [<client.ip>]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
[17:00:15:118:C] AUTH LOGIN

11/23/2021 5:01:15 PM - System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我已经尝试了很多事情,以下可能是一些值得注意的事情:

  1. 防火墙允许端口 587
  2. 已禁用防火墙
  3. 已禁用 Windows Defender
  4. 尝试了不同的 TLSSecurityProtocol
  5. 在 smtp.gmail.com 和 smtp.office365.com 上都试过了 - 同样的故障
  6. 在其他版本的代码中,ServerCertificateValidationCallback被覆盖为始终返回 true。我实际上发现了一些 windows 事件错误,说The certificate received from the remote server was issued by an untrusted certificate authority. Because of this, none of the data contained in the certificate can be validated. The TLS connection request has failed. The attached data contains the server certificate.

我只是不知道还能做什么。这似乎是基础设施问题,无论是来自域、证书、服务器网络(云服务器)等,但我想在让他们参与之前确保这一点。或者至少,给他们一个起点,让他们知道要看什么或从哪里看。

相关内容