CDO.消息在 VBS 中有效,但在 ASP 中不起作用



虽然VBS代码工作正常,但在运行ASP代码时出现此错误:

"传输无法连接到服务器。(-2147220973(">

我尝试将SMTP服务器端口更改为25和587,但没有成功。

我已经在谷歌上搜索了一个解决方案,但还没有找到。

任何帮助将不胜感激。

ASP 代码如下:

<% @Language="VBScript" %>
<%  Option Explicit
On Error Resume Next
'*
'*  Declare Constants
'*
Const cASP = "gmail.asp"
Const cCFG = "http://schemas.microsoft.com/cdo/configuration/"
Const cEMA = "{user}@gmail.com"
Const cPWD = "{password}"
Const cSMT = "smtp.gmail.com"
'*
'*  Send Email
'*
Dim oCDO
Dim oCFG
Set oCDO = Server.CreateObject("CDO.Message")
Set oCFG = Server.CreateObject("CDO.Configuration")
oCFG.Fields.Item(cCFG & "sendusing") = 2
oCFG.Fields.Item(cCFG & "sendusername") = cEMA
oCFG.Fields.Item(cCFG & "sendpassword") = cPWD
oCFG.Fields.Item(cCFG & "smtpserver") = cSMT
oCFG.Fields.Item(cCFG & "smtpserverport") = 465
oCFG.Fields.Item(cCFG & "smtpauthenticate") = 1
oCFG.Fields.Item(cCFG & "smtpusessl") = True
oCFG.Fields.Item(cCFG & "smtpconnectiontimeout") = 10
oCFG.Fields.Update
oCDO.Configuration = oCFG 
oCDO.From = cEMA
oCDO.To = cEMA
oCDO.Subject = cSMT & " via " & cASP
oCDO.HTMLBody = "<h1>" & Now & "</h1>"
oCDO.Send
If Err.Number <> 0 Then
Response.Write "<li>" & Err.Description & " (" & Err.Number & ")"
Else
Response.Write "<li>Email Sent!"
End If
Set oCFG = Nothing
Set oCDO = Nothing
%>

VBS 代码如下:

Option Explicit
'*
'*  Declare Constants
'*
Const cVBS = "gmail.vbs"
Const cCFG = "http://schemas.microsoft.com/cdo/configuration/"
Const cEMA = "{user}@gmail.com"
Const cPWD = "{password}"
Const cSMT = "smtp.gmail.com"
'*
'*  Send Email
'*
Dim oCDO
Dim oCFG
Set oCDO = CreateObject("CDO.Message")
Set oCFG = CreateObject("CDO.Configuration")
oCFG.Fields.Item(cCFG & "sendusing") = 2
oCFG.Fields.Item(cCFG & "sendusername") = cEMA
oCFG.Fields.Item(cCFG & "sendpassword") = cPWD
oCFG.Fields.Item(cCFG & "smtpserver") = cSMT
oCFG.Fields.Item(cCFG & "smtpserverport") = 465
oCFG.Fields.Item(cCFG & "smtpauthenticate") = 1
oCFG.Fields.Item(cCFG & "smtpusessl") = True
oCFG.Fields.Update
oCDO.Configuration = oCFG
oCDO.From = cEMA
oCDO.To = cEMA
oCDO.Subject = cSMT & " via " & cVBS
oCDO.HTMLBody = "<h1>" & Now & "</h1>"
oCDO.Send
Set oCDO = Nothing
Set oCFG = Nothing

以下内容对我有用:

.Item(sch & "sendusing") = 2
.Item(sch & "smtpconnectiontimeout") = 900
.Item (sch & "smtpusessl") = true
.Item(sch & "smtpserver") = s_remote_host
.Item(sch & "smtpserverport") = 587 'or 465
.Item(sch & "smtpauthenticate") = 1 'if error still, double-check this
.Item(sch & "sendusername") = SMAUTHUSER
.Item(sch & "sendpassword") = SMAUTHPASS

相关内容

最新更新