Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent: Error Log in a separate file 1

Status
Not open for further replies.

affu2000

Programmer
Sep 28, 2005
4
0
0
US
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]

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
 
Thanks for the answer PH.

But is there any way you or anyone can show me how to achieve that for the above said code.
 
Replace the WScript.Echo calls with calls to the WriteLine method of the TextStream object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top