VB Script - Undefined variable
I'm getting 'variable is undefined', I'm guessing this has something to do with the scope of variables in vbscript, but my knowledge is limited with this.
I know the loading of the email addresses works and the actual emailing because I have checked these separately. I'm trying to loop through a list of email addresses and send the log file to each..
Any additional information would be great!
First, there is a var array at the top of the file:
dim emails()
function getEmailAddresses()
dim objFSO
dim objConfigFile
dim strLine
dim iCounter
const ForReading = 1, ForWriting = 2, ForAppending = 8
set objFSO = createobject("Scripting.FileSystemObject")
set objConfigFile = objFSO.OpenTextFile("emailAddresses.config", ForReading)
iCounter = 0
do while not objConfigFile.AtEndOfStream
redim preserve emails(iCounter)
strLine = trim(objConfigFile.ReadLine)
emails(iCounter) = strLine
iCounter = iCounter + 1
loop
objConfigFile.Close
end function
function writetolog(strLogtext)
dim objFSO
dim objLogfile
const ForReading = 1, ForWriting = 2, ForAppending = 8
set objFSO = createobject("Scripting.FileSystemObject")
set objLogfile = objFSO.OpenTextFile("xxx.log", ForAppending, true)
objLogfile.Writeline now() & " - " & strLogText
objLogfile.Close
call EmailLogFile(strLogText)
end function
function EmailLogFile(bodyText)
for each emailAddress in emails
set objEmail = CreateObject("CDO.Message")
objEmail.From = "File.Mover@xxxxxxx.xxx"
objEmail.To = emailAddress
objEmail.Subject = "File Move Log"
objEmail.Textbody = bodyText
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"xxxxxx"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")开发者_Python百科 = 25
objEmail.Configuration.Fields.Update
objEmail.Send
next
end function
It doesn't look like you're calling getEmailAddresses()
anywhere so your file won't be read and your emails
array won't be populated
What line is the undefined var at? Or what is the var name?
Either way, 'strLogText' is not defined anywhere. Also, if this is a classic ASP page put an Option Explicit statement at the top.
精彩评论