CDO.message vbscript-传输连接失败

CDO.message vbscript-传输连接失败,vbscript,cdo.message,Vbscript,Cdo.message,我在分公司的Windows7机器上有一个vbscript。它很好用。我将代码复制到第二台分支办公室的Windows 7计算机上,结果出错。我没有主意了 两台Windows计算机都安装了MS Outlook Do While asObj.ConnectionState = asCONN_CONNECTED WeekDayNumber = Weekday(Now()) HourNumber = Hour(Now()) 'WScript.Echo as

我在分公司的Windows7机器上有一个vbscript。它很好用。我将代码复制到第二台分支办公室的Windows 7计算机上,结果出错。我没有主意了

两台Windows计算机都安装了MS Outlook

 Do While asObj.ConnectionState = asCONN_CONNECTED
        WeekDayNumber = Weekday(Now())
        HourNumber = Hour(Now())
        'WScript.Echo asObj.HasData
        If asObj.HasData Then
        WScript.Echo asObj.ReceiveString
            WriteData asObj.ReceiveString
            uploadData
            CycleDate = Now()
            asObj.Sleep 300
        Else
            If WeekDayNumber > 1 And WeekDayNumber < 7 And HourNumber > 8 And HourNumber < 17 Then
                DiffInMinutes = DateDiff("n",CycleDate,Now())
                'WScript.Echo "Day=" & WeekDayNumber & vbCrLf & "Hour=" & HourNumber & vbCrLf & "cycle=" & CycleDate & vbCrLf & "diff=" & DiffInMinutes & vbCrLf & " Now=" & Now()
                If DiffInMinutes > 2 Then
                    SendAlertEmail
                    WriteData "Alert email sent  " & Now() & vbCrLf
                    WScript.Echo cyclecounter & " no data"
                    CycleDate = Now()
                    ' Sleep 5 minutes
                    asObj.Sleep 1000
                End If
            End If
       End If
    Loop
' And finally, disconnect
    WScript.Echo "Disconnect -- we should never get to this point. Call Chris!"
    asObj.Disconnect
Else
    WScript.Echo "bad connection. You have to restart the script"
End If

    Sub WriteData(sData)
        Const ForAppending = 8
        Const OutputFile = "d:\calldata\calldata_data\CallData_$DATE$mtp.txt"

        Dim DateNow
        Dim varDate
        Dim objFile
        Dim objFSO

        ' WScript.Echo sData

        Datenow = Date()
        varDate = Year(DateNow) & Right("0" & Month(DateNow), 2) & Right("0" & Day(DateNow), 2)

        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.OpenTextFile(Replace(OutputFile, "$DATE$", varDate), ForAppending, True)
        objFile.WriteLine sData
        objFile.Close

        Set objFile = Nothing
        Set objFSO = Nothing
    End Sub

Sub uploadData

Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")

objShell.Run "c:\calldata\FTPupload.vbs",10,True 
objShell.Run "c:\calldata\updateCallData.vbs",10,True
' Using Set is mandatory
Set objShell = Nothing

End Sub
Sub SendAlertEmail

Set email = CreateObject("CDO.Message")
WScript.Echo "step 1"

email.Subject = "MTP - Possible phone time collection failure"
email.From = "x@gmail.com"
email.To = "x@x.com;x@x.com;x@x.com"
email.TextBody = Now() & "  The collection of phone time that is done on the MTP Domain Controller seems to have failed. There has been no data for quite a while."

email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication  
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "x@gmail.com"
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"


email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.gmail.com"
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25

email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30 

email.Configuration.Fields.Update
email.Send
If Err Then
         WScript.Echo "SendMail Failed:" & Err.Description
    End If
set email = Nothing
'WScript.Echo"step 2"
End Sub
asObj.ConnectionState=asCONN\u连接时执行 WeekDayNumber=工作日(现在为()) HourNumber=小时(现在() 'WScript.Echo asObj.HasData 如果asObj.HasData,则 WScript.Echo asObj.ReceiveString WriteData asObj.ReceiveString 上传数据 CycleDate=Now() 睡300 其他的 如果工作日数>1,工作日数<7,小时数>8,小时数<17,则 DiffInMinutes=DateDiff(“n”,CycleDate,Now()) 'WScript.Echo“Day=“&WeekDayNumber&vbCrLf&”Hour=“&HourNumber&vbCrLf&”cycle=“&CycleDate&vbCrLf&”diff=“&DiffInMinutes&vbCrLf&”Now=“&Now() 如果DiffInMinutes>2,则 发送警报电子邮件 WriteData“已发送警报电子邮件”&Now()&vbCrLf WScript.Echo循环计数器&“无数据” CycleDate=Now() “睡5分钟 asObj.睡眠1000 如果结束 如果结束 如果结束 环 最后,断开连接 Echo“断开连接--我们永远不应该到这一点。给Chris打电话!” 断开连接 其他的 Echo“连接错误。必须重新启动脚本” 如果结束 分写数据(sData) 出现的常数=8 Const OutputFile=“d:\calldata\calldata\u data\calldata\u$DATE$mtp.txt” 暗淡的日期现在 Dim varDate Dim objFile Dim objFSO 'WScript.Echo sData Datenow=Date() varDate=Year(DateNow)和Right(“0”和Month(DateNow),2)和Right(“0”和Day(DateNow),2) 设置objFSO=CreateObject(“Scripting.FileSystemObject”) 设置objFile=objFSO.OpenTextFile(Replace(OutputFile,“$DATE$”,varDate),用于显示,True) objFile.WriteLine sData objFile.Close 设置objFile=Nothing 设置objFSO=Nothing 端接头 次上传数据 昏暗的奥布舍尔 设置objShell=Wscript.CreateObject(“Wscript.Shell”) 运行“c:\calldata\FTPupload.vbs”,10,True 运行“c:\calldata\updateCallData.vbs”,10,True '必须使用集合 Set objShell=Nothing 端接头 子系统发送警报电子邮件 设置email=CreateObject(“CDO.Message”) Echo“步骤1” email.Subject=“MTP-可能的电话时间收集失败” email.From=”x@gmail.com" email.To=”x@x.com;x@x.com;x@x.com" email.TextBody=Now()&“在MTP域控制器上完成的电话时间收集似乎失败。很久没有数据了。” email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate“”=1“基本(明文)身份验证 email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername") = "x@gmail.com" email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendpassword“”=“密码” email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing")=2 email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver“”=“smtp.gmail.com” email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 email.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30 email.Configuration.Fields.Update 发送电子邮件 如果有错误,那么 WScript.Echo“发送邮件失败:”&错误说明 如果结束 设置电子邮件=无 'WScript.Echo“步骤2” 端接头
Gmail在465上,指定的数量不足

这是工作代码

Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = "d@gmail.com"

emailObj.To       = "d@gmail.com"

emailObj.Subject  = "Test CDO"
emailObj.TextBody = "Test CDO"

emailObj.AddAttachment "c:\windows\win.ini"

Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = true 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = "d"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "Password1"
emailConfig.Fields.Update

emailObj.Send

If err.number = 0 then Msgbox "Done"

Gmail在465上,指定的数量不够

这是工作代码

Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = "d@gmail.com"

emailObj.To       = "d@gmail.com"

emailObj.Subject  = "Test CDO"
emailObj.TextBody = "Test CDO"

emailObj.AddAttachment "c:\windows\win.ini"

Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = true 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = "d"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "Password1"
emailConfig.Fields.Update

emailObj.Send

If err.number = 0 then Msgbox "Done"

我以前收到过这个错误,对我来说是一台计算机和另一台计算机之间的安全权限。检查两台机器上的访问权限是否有差异是值得的。

我以前收到过这个错误,对我来说,这是一台计算机和另一台计算机之间的安全权限。检查这两台机器上的访问权限是否有差异是值得的。

在这种情况下,当它在一台机器上工作而在另一台机器上工作时,很少会出现代码/脚本问题。毕竟,它对其中一个有效!您需要开始考虑这两台计算机之间的差异,并开始进行故障排除。您是否以同一用户身份登录这两个站点?他们是否安装了相同的Windows更新?它们都是32位还是64位?防火墙上有IP或MAC地址限制吗?在这种情况下,当它在一台机器上工作而不是在另一台机器上工作时,很少会出现代码/脚本问题。毕竟,它对其中一个有效!您需要开始考虑这两台计算机之间的差异,并开始进行故障排除。您是否以同一用户身份登录这两个站点?他们是否安装了相同的Windows更新?它们都是32位还是64位?防火墙上有IP或MAC地址限制吗?等,等使用465,我得到以下错误;多步骤OLE DB操作生成错误。检查每个OLE DB状态值。导致错误的行是;设置objFile=objFSO.OpenTextFile(Replace(OutputFile,“$DATE$”,varDate),ForAppending,True)我不得不注册cdo.dll,它现在似乎正在工作;多步骤OLE DB操作生成错误。检查每个OLE DB状态值。导致错误的行是;设置objFile=objFSO.OpenTextFile(Replace(OutputFile,“$DATE$”,varDate),ForAppending,True)我不得不注册cdo.dll,它现在似乎可以工作了。它看起来和r一样