Microsoft VBScript 运行时错误 错误描述:需要的对象:'Server'
Microsoft VBScript runtime error Error Description: Object required: 'Server'
我正在尝试 运行 每天 sql 使用 SMTP 服务器和 CDONT 邮件对象向我的客户端发送邮件的作业。已经有适合我的代码。最近我将我的服务器从 Microsoft Server 2003 升级到 2012,并将 Sql 服务器 2005 升级到 2014。
下面的代码在服务器的经典 asp 中运行良好。但是在 sql 作业中出现错误
Set objEMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi@xx.in"
objEMail.From ="hello@yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
Executed as user: NT Service\SQLSERVERAGENT. Error Code: 0 Error Source= Microsoft VBScript runtime error Error Description: Object required: 'Server' #
Server
是特定于 ASP Classic 的对象。
您的代码可能 运行 由 Windows 脚本宿主 (wscript.exe / cscript.exe) 提供,它有自己的 CreateObject
功能。
只需删除 Server.
即可。
Set objEMail = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi@xx.in"
objEMail.From ="hello@yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
郑重声明,Server
在 ASP Classic 中也是可选的,上面的代码在两种环境中都适用。
我正在尝试 运行 每天 sql 使用 SMTP 服务器和 CDONT 邮件对象向我的客户端发送邮件的作业。已经有适合我的代码。最近我将我的服务器从 Microsoft Server 2003 升级到 2012,并将 Sql 服务器 2005 升级到 2014。
下面的代码在服务器的经典 asp 中运行良好。但是在 sql 作业中出现错误
Set objEMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi@xx.in"
objEMail.From ="hello@yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
Executed as user: NT Service\SQLSERVERAGENT. Error Code: 0 Error Source= Microsoft VBScript runtime error Error Description: Object required: 'Server' #
Server
是特定于 ASP Classic 的对象。
您的代码可能 运行 由 Windows 脚本宿主 (wscript.exe / cscript.exe) 提供,它有自己的 CreateObject
功能。
只需删除 Server.
即可。
Set objEMail = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi@xx.in"
objEMail.From ="hello@yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
郑重声明,Server
在 ASP Classic 中也是可选的,上面的代码在两种环境中都适用。