从 VBScript 发送电子邮件时出错

Error sending email from VBScript

当运行以下脚本时,我得到错误-2147220975和传输代码错误:0x80040217

on error resume next

Const schema   = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf

Set oMsg      = CreateObject("CDO.Message")
oMsg.From     = "tom.watt.vulpes@gmail.com"  
oMsg.To       = "tom.watt.vulpes@gmail.com"    
oMsg.Subject  = "Test from VBScript"
oMsg.TextBody = "If you can read this, the script worked!"
objMsg.AddAttachment "C:\BLA_BLA.txt"

Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver")       = "smtp.gmail.com" 
oConf.Fields(schema & "smtpserverport")   = 465              
oConf.Fields(schema & "sendusing")        = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic         
oConf.Fields(schema & "smtpusessl")       = True             
oConf.Fields(schema & "sendusername")     = "tom.watt.vulpes@gmail.com" 
oConf.Fields(schema & "sendpassword")     = "PASSWORD"      
oConf.Fields.Update()

oMsg.Send()


If Err Then
    resultMessage = "ERROR " & Err.Number & ": " & Err.Description
    Err.Clear()
Else
    resultMessage = "Message sent ok"
End If

Wscript.echo(resultMessage)

我已经尝试了无数来自 Internet 的脚本,但其中 none 似乎有效。我究竟做错了什么? 谢谢,汤姆

编辑:我是 运行 Windows 10

传输代码错误:0x80040217 可能是一些不同的东西,具体取决于情况。下面的链接应该会引导您朝着正确的方向前进...

Overflowing Stack

MSDN

我发现与此相关的可能有帮助的是我想使用此脚本的域有一个 SPF 记录附加了一个硬故障,因此只有他们的特定电子邮件服务器可以工作在我的例子中是 Office 365,但在测试时我正在使用他们的 ISP 并试图通过他们进行未经身份验证的中继。

所以还要检查 SPF,希望这对您有所帮助。

科齐