【发布时间】:2021-05-22 14:25:45
【问题描述】:
我正在尝试使用 VBA 中的 CDO.message 从 Office 355 上的帐户发送电子邮件,以自动执行 Microsoft Access 中的一些电子邮件任务。
代码来自this源。
我明白了
“传输连接服务器失败”
根据我的研究,这似乎是 TLS 身份验证的问题。
Dim objMessage, objConfig, fields
Set objMessage = New CDO.message
Set objConfig = New CDO.Configuration
Set fields = objConfig.fields
With fields
.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 '465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "noreply@domain.ca"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "passowrd"
'.Item("http://schemas.microsoft.com/cdo/configuration/sendtls") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
Set objMessage.Configuration = objConfig
With objMessage
.subject = "Test Message"
.From = "noreply@domain.ca"
.To = "noreply@domain.ca"
.HTMLBody = "Test Message"
End With
objMessage.Send
编辑:无论用户如何,都需要从同一个电子邮件地址发送电子邮件,因此,我不相信使用 Outlook 会起作用。
编辑 2:我的 ISP 似乎阻止了端口 25 和 465。使用 telnet 我能够从端口 587 获得响应,但是,我得到了与以前相同的错误(除了这次我立即得到它,而不是在很长一段时间后得到它)。可能是由于缺少 TLS 身份验证。
【问题讨论】:
-
smtpserverport 25?大多数 ISP 都会阻止它。
-
@StureS 你对使用什么端口有什么建议吗?我尝试了端口 465(在网上找到了该建议),我得到了同样的错误。
-
尝试 587 与 TLS
-
@StureS 使用 587 和 TLS 我收到错误“服务器拒绝了发件人地址...发送邮件需要 STARTTLS”
-
您的登录程序有问题。这是合乎逻辑的。您实际上是在声明您想从一个人发送一封电子邮件,无论实际发件人是谁。这就是垃圾邮件的工作原理,不会被允许。
标签: excel vba email ms-access cdo.message