【发布时间】:2016-10-28 05:27:38
【问题描述】:
我正在尝试在 Excel VBA 中发送电子邮件。根据我对 Internet 的研究,我启用了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、用户名、密码、服务器端口...)。 不知道哪里出错了。
【问题讨论】:
-
您是否在 Powershell 中为 .From 和 sendusername 使用完全相同的值?听起来服务器无法识别发件人地址 - 您的示例具有不同的用户名/发件人值。
-
@dbmitch username 和 from 值在我的情况下是不同的;用户名是 LANID,发件人是真实的电子邮件地址。它适用于 PowerShell。
-
很奇怪。这适用于 GMail。
-
但是我遇到了各种各样的问题来让它与 hotmail 一起工作。
-
@Rodger 我尝试按照说明进行操作;但是,Microsoft 更新了门户的布局,因此我找不到说明中指定的那些模块。我需要做更多的研究。