首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CDO.Message工作在VBS中,而不是ASP。

CDO.Message工作在VBS中,而不是ASP。
EN

Stack Overflow用户
提问于 2019-08-22 20:34:11
回答 1查看 374关注 0票数 0

虽然VBS代码运行良好,但在运行ASP代码时会出现以下错误:

“传输未能连接到服务器。(-2147220973)”

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

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

任何帮助都将不胜感激。

ASP代码如下:

代码语言:javascript
复制
<% @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代码如下:

代码语言:javascript
复制
    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
EN

回答 1

Stack Overflow用户

发布于 2019-08-28 18:08:39

以下几点对我来说是可行的:

代码语言:javascript
复制
.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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57616704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档