-1

Hi I have my vbs script below to send email by executing xp_sendmail.

ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=myserver" 
Set dbconn = CreateObject("ADODB.Connection")
dbconn.Open ConnectionString

DIM cmd
SET cmd = CreateObject("ADODB.Command")
SET cmd.ActiveConnection = dbconn
cmd.CommandText = "xp_sendmail"
cmd.CommandType = 4  'adCmdStoredProc
Dim email = "me@me.com"
Dim subj = "test"
Dim msg = "message"

cmd.Parameters("@Recipients") = email
cmd.Parameters("@Subject") = subj
cmd.Parameters("@message") = msg 
cmd.Execute

This gives an error on the line:

Dim email = "me@me.com"

Error: Expected end of element. Any help would be appreciated.

mulla
  • 143
  • 1
  • 11
John F
  • 142
  • 2
  • 13

1 Answers1

0

Try to change this:

Dim email = "me@me.com"
Dim subj = "test"
Dim msg = "message"

cmd.Parameters("@Recipients") = email
cmd.Parameters("@Subject") = subj
cmd.Parameters("@message") = msg 

To this:

cmd.parameters.Append cmd.CreateParameter("Recipients", adVarChar, adParamInput, 50, "me@me.com") 
cmd.parameters.Append cmd.CreateParameter("Subject", adVarChar, adParamInput, 50, "test") 
cmd.parameters.Append cmd.CreateParameter("Message", adVarChar, adParamInput, 50, "message") 

In another words you need to append parameters and than execute command. Info about CreateParameter is here about Append here.

gofr1
  • 15,741
  • 11
  • 42
  • 52
  • Hi @gofr1. I tried your solution but now it gives me an error: Arguments are of wrong type etc.. 800A0BB9, ADODB.Command – John F Jul 31 '16 at 05:28
  • Try adVarWChar, it is similar to nvarchar SQL server datatype. – gofr1 Jul 31 '16 at 06:48