我正在尝试在Excel VBA中发送电子邮件。根据我对互联网的研究,我启用了Microsoft CDO for Windows 2000 Library
并编写了我的VBA代码,如下所示:
Sub SendCDOMail()
Dim objCDOMsg As Object
Set objCDOMsg = CreateObject("CDO.Message")
'CDO Configuration
With objCDOMsg.Configuration.Fields
'
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Server port (typically 25, 587)
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
'SMTP server IP or Name
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'SMTP Account User ID
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxx@bbbb.com"
'SMTP Account Password
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxxx"
'Use SSL for the connection (False or True)
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Update
End With
'CDO Message
objCDOMsg.Subject = "TEST Subject"
objCDOMsg.From = "xx@xx.com"
objCDOMsg.To = "xx@xx.com"
objCDOMsg.TextBody = "TEST Body"
objCDOMsg.Send
End Sub
但是,我收到错误说:
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
我也尝试使用PowerShell进行相同的配置,并且它有效(smtpserver,用户名,密码,服务器端口......)。 我不知道哪里可能出错。
答案 0 :(得分:0)
这是:https://technet.microsoft.com/en-us/library/mt210446(v=exchg.150).aspx - 请注意,这是在Office365部分中的"如何设置多功能设备或应用程序以使用Office 365发送电子邮件,",所以可能在你身边也有其他东西。
这表示您正在连接到SMTP客户端提交端点(smtp.office365.com),该端点不能用于直接发送。对于直接发送,使用适用于您的Office 365租户的MX端点,该端点以" mail.protection.outlook.com结尾。" 您可以按照以下步骤找到您的MX端点在Full configuration instructions for direct send.