【问题标题】:Use CDO Send Emails in Excel VBA Not Working在 Excel VBA 中使用 CDO 发送电子邮件不起作用
【发布时间】: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 更新了门户的布局,因此我找不到说明中指定的那些模块。我需要做更多的研究。

标签: vba excel email


【解决方案1】:

这里是:https://technet.microsoft.com/en-us/library/mt210446(v=exchg.150).aspx - 请注意,这是在“如何设置多功能设备或应用程序以使用 Office 365 发送电子邮件”的 Office365 部分中,因此可能还有其他内容适合您.

这表示您正在连接到 SMTP 客户端提交端点 (smtp.office365.com),该端点不能用于直接发送。对于直接发送,使用 Office 365 租户的 MX 端点,以“mail.protection.outlook.com”结尾。您可以按照Full configuration instructions for direct send. 中的步骤找到您的 MX 端点

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2013-10-03
    • 2021-06-09
    • 2016-01-05
    • 2012-11-11
    • 2022-01-03
    • 2017-05-23
    • 2023-03-11
    相关资源
    最近更新 更多