我试图运行每日sql作业,使用SMTP服务器和CDONT Mail对象向我的客户端发送邮件。已经有适合我的代码。最近我将我的服务器从microsoft Server 2003升级到2012和Sql server 2005升级到2014.
以下代码在Classic asp服务器中运行良好。但是在sql job getting error中
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
以用户身份执行:NT Service \ SQLSERVERAGENT。错误代码:0错误源= Microsoft VBScript运行时错误错误说明:所需对象:'服务器'#
答案 0 :(得分:0)
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中也是可选的,上述代码可以在两种环境中使用。