[英]CDO.Message works in VBS but not ASP
盡管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
以下對我有用:
.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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.