Rejish
Rejish

Reputation: 23

Microsoft VBScript runtime error Error Description: Object required: 'Server'

Am trying to run daily sql job which sends mail to my client using SMTP Server and CDONT Mail objects . Already has the code which works fine for me. Recently i have upgraded the my server from microsoft Server 2003 to 2012 and Sql server 2005 to 2014.

This code below works fine in Classic asp in server. But in 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 = "[email protected]"
objEMail.From ="[email protected]"
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' #

Upvotes: 0

Views: 3749

Answers (1)

Tomalak
Tomalak

Reputation: 338426

Server is an object that is specific to ASP Classic.

Your code is probably run by the Windows Script Host (wscript.exe / cscript.exe), which has its own CreateObject function.

Simply remove the Server. to make it work.

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 = "[email protected]"
objEMail.From ="[email protected]"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send

Set objEMail = Nothing

For the record, the Server is optional in ASP Classic as well, the above code would work in both environments.

Upvotes: 1

Related Questions