While the VBS code works fine, I get this error when I run the ASP code:
"The transport failed to connect to the server. (-2147220973)"
I've tried changing the SMTP Server Port to 25 and 587 without success.
I've Googled for a solution but have not found one yet.
Any help would be appreciated.
ASP code below:
<% @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 code below:
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
The following works for me:
.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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.