The following script is run to send emails to candidates applying for a position.
I want to log any kind of errors that take place during this process and save them in a separate file (like a .log or .dat)
Please help me.![[ponder] [ponder] [ponder]](/data/assets/smilies/ponder.gif)
Thanks in advance
Affu2000
I want to log any kind of errors that take place during this process and save them in a separate file (like a .log or .dat)
Please help me.
![[ponder] [ponder] [ponder]](/data/assets/smilies/ponder.gif)
Code:
' VBScript source code
Set db = CreateObject("ADODB.Connection")
set rsEmails = CreateObject("ADODB.Recordset")
Set objMessage = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
objConfig.Fields.item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objConfig.Fields.item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "smtp.aaaa.org"
objConfig.Fields.Update
db.Open "Driver={SQL Server};Server=abcd;Database=affu;Uid=A423;Pwd=bs1 900"
rsEmails.Open "SELECT FromEmail,ToEmail, SubjectLine, SentOn, EmailBOdy FROM EmailData WHERE (Cancelled IS NULL OR Cancelled=0) AND (SentOn IS NULL) AND (DATEDIFF(hh, ScheduledOn, GETDATE()) > 5) ;", db, 3, 3
Set objMessage.Configuration = objConfig
totalrecords=rsEmails.RecordCount
wscript.echo "Total Records=" & totalrecords
recno=1
prevemail=""
errorcnt=0
on error resume next
while not rsEmails.EOF and (errorcnt < 10)
if prevemail=rsEmails("ToEmail") then
errorcnt=errorcnt+1
wscript.echo rsEmails("toemail") & " ERROR!!!!"
else
objMessage.To = rsEmails("ToEmail")
objMessage.From = rsEmails("FromEmail")
objMessage.Subject = rsEmails("SubjectLine")
objMessage.TextBody = rsEmails("EmailBody")
objMessage.Send
if err.number > 0 then
errmsg=err.Description
wscript.echo rsEmails("Recipient") & " " & errmsg
if len(errmsg) > 90 then
errmsg=left(errmsg,90)
end if
rsEmails("ErrorMessage")=errmsg
err.Clear
else
wscript.echo rsEmails("toemail") & " " & formatPercent(recno/totalrecords,0,true,true,true)
recno=recno+1
rsEmails("SentOn")=now()
end if
rsEmails.Update
prevemail=rsEmails("ToEmail")
errorcnt=0
end if
rsEmails.MoveNext
wend
rsEmails.Close
db.Close
set rsEmails = nothing
set objMessage = nothing
set objConfig = nothing
set db = nothing
Thanks in advance
Affu2000