CDO.Message可在VBS中工作,但不能在ASP中工作

时间:2019-08-22 20:34:11

标签: vbscript asp-classic cdo.message

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

  

“传输无法连接到服务器。(-2147220973)”

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

我已经在Google上找到了一种解决方案,但尚未找到。

任何帮助将不胜感激。

下面的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

1 个答案:

答案 0 :(得分:0)

以下对我有用:

.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