2016-07-26 45 views
-1

您好我有我的vbs腳本通過執行xp_sendmail來發送電子郵件。在vbs中調用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 = "[email protected]" 
Dim subj = "test" 
Dim msg = "message" 

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

這給上線的錯誤:

Dim email = "[email protected]" 

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

+0

如果您刪除'adCmdStoredProc? –

+1

'Dim email' and another line'email =「[email protected]」' – 2016-07-26 04:45:35

+0

嗨@noodles,我試過了你的建議,但現在它給了我一個錯誤:找不到對應於請求的名稱的集合中的項目或序。 line:cmd.Parameters(「@ Recipients」)=電子郵件 –

回答

0

試圖改變這一點:

Dim email = "[email protected]" 
Dim subj = "test" 
Dim msg = "message" 

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

要這樣:

cmd.parameters.Append cmd.CreateParameter("Recipients", adVarChar, adParamInput, 50, "[email protected]") 
cmd.parameters.Append cmd.CreateParameter("Subject", adVarChar, adParamInput, 50, "test") 
cmd.parameters.Append cmd.CreateParameter("Message", adVarChar, adParamInput, 50, "message") 

換句話說,你需要追加參數而不是執行命令。有關CreateParameter的信息是hereAppendhere

+0

Hi @ gofr1。我試過你的解決方案,但現在它給了我一個錯誤:參數是錯誤的類型等.. 800A0BB9,ADODB.Command –

+0

嘗試adVarWChar,它類似於nvarchar SQL服務器數據類型。 – gofr1