CDOSYS 错误 '80040213' - 无法连接到服务器

CDOSYS error '80040213' - failed to connect to server

我有一个 Windows Server 2003 R2 运行 IIS 和一个使用经典 ASP 的网站。 尝试使用我们自己(外部)托管的 o​​ffice365 交换服务器使用 CDOSYS 发送电子邮件。

我收到以下错误

CDO.Message.1 error '80040213'
The transport failed to connect to the server.

这通常意味着 3 个问题之一: 1.错误的SMTP服务器/端口 2. 不正确 login/password 3. 根据 SMTP 服务器,FROM 地址无效(域错误)

SMTP 服务器和端口根据供应商是正确的。 login/password 是正确的,因为我可以使用这些详细信息登录邮件帐户 FROM 地址是正确的,因为这是我用来登录的帐户。

我可以通过该地址和端口从 Web 服务器远程登录到 Exchange 服务器,因此至少可以从服务器建立连接。

所以目前我不知道问题出在哪里。 有人对我需要查看的其他内容有任何指示吗?

这是网站正在使用的配置

myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.office365.com"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=587
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

您是否在 Office 365 中设置了 SMTP 中继?

从 Office 365 管理员转到:

  1. 管理员 > Exchange
  2. 邮件流 > 连接器
  3. 单击添加新的 SMTP 中继连接器
  4. Select 从 "your organization's email server" 到 "office 365"
  5. 为连接器命名和描述
  6. Select 通过 IP 地址验证并添加您的网络服务器 IP
  7. 保存

尝试Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25

对于 Office 365,cdo 似乎更喜欢端口 25,即使在使用身份验证时也是如此。

如果有帮助,这里是一个久经考验的配置

Set iConfg = Server.CreateObject("CDO.Configuration")
Set Flds = iConfg.Fields
With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myusername"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
        .Update
End With
objMail.Configuration = iConfg

好吧,我最终解决了这个问题。 我需要使用不同的方法连接到 office365 服务器。 所以现在一切正常。

尝试

.Item("http://schemas.microsoft.com/cdo/configuration/smtpsendtls") = 1

而不是

.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1