我正在尝试更改旧的Excel表单以通过Office 365帐户而不是GMail发送电子邮件,但几乎所有操作都会给我The transport failed to connect to the server
错误。
以下是相关代码:
Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1
Set SMTP_Config = CDO_Config.Fields '
With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strFrom
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = emailFromPassword
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
With CDO_Mail
Set .Configuration = CDO_Config
End With
CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.HTMLBody = strBody
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send
Error_Handling:
If Err.Description <> "" Then
MsgBox (Err.Description)
我已经尝试了一些我能想到的相关的东西(然后是一些):
smtp.office365.com
和pod51010.office365.com
大多数情况下都会给我前面提到的错误。有些挂起无限期(例如使用端口25)。
关闭SSL会让端口587上的连接通过。即使我们对此没问题,它也会产生不同的错误。 The server rejected the sender address. The server response was: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [...outlook.com]
但是,我已经验证了凭据是否正确。从我读到的这意味着我无法发送带有SSL的邮件?所以这不是一个选择。
我正在使用Excel 2010。
我错过了什么,或者出于某种原因这是不可行的?