Using a Function in an Automated Email

Basically, I have a this script which I've written that is meant to send out a daily digest of news entered into the site. The news appears on the site fine, and the method of sneding the email works fine. What I am having a problem with though, is producing the results of a loop through the news table in the email body. The email is fine up until the function call at the very end, where it doesn't output anything.

Anyone have any thoughts? Any help would be greatly appreciated. Note that some minor things have been ommitted from this script due to it containing privilaged information.



Dim DigestRS
Dim objCWRS

Set DigestRS = objConn1.Execute("SELECT * FROM subs WHERE digest = ""on""")

Set objDRS = objConn1.Execute("SELECT * FROM current ORDER BY date DESC")

Function currentLoop()
Do While Not objDRS.EOF
Response.Write("<table border=""0"" bgcolor=" & objRS1("tableBody").Value & " width=""100%"">")
Response.Write("<tr>")
Response.Write("<td valign=""top"" colspan=""2"" bgcolor=" & objRS1("tableHead").Value & "><font size=""1"">" & objDRS("date") & "</td>")
Response.Write("</tr>")
Response.Write("<tr>")
Response.Write("<td colspan=""2""><font size=""2""><b>" & objDRS("title") & "</b></td>")
Response.Write("</tr>")
Response.Write("<tr>")
Response.Write("<td><font size=""1"">(" & objDRS("classification") & ") " & objDRS("comment") & "</td>")
Response.Write("</tr>")
Response.Write("<tr><td colspan=""2""><hr></td></tr>")
Response.Write("</table>")
objDRS.MoveNext
Loop
End Function

CLoop = currentLoop()

'########### My debugging section - shows last time footer.asp was run
'Response.Write Application("LastScheduledRun") & "<br />" & vbCrLf
'Response.Write Now() & "<br />" & vbCrLf
'Response.Write DateDiff("d", Application("LastScheduledRun"), Now()) _
' & "<br />" & vbCrLf

If DateDiff("d", Application("LastScheduledRun"), Now()) > 0 Then
' This is where you put the commands you want to run on the
' schedule set up by the above condition.
Do while Not DigestRS.EOF
set myMail = createobject("CDONTS.NewMail")

myMail.send "Webmaster", DigestRS("email"), ""& siteNameFull &" Digest for "& date() &"", "As per your request, you are receiving daily email digests of the Current *** reports from the "& siteNameFull &" Portal. Following are the items entered yesterday in their entirety. This is an automated email, so please do not respond."& currentLoop() &""

set myMail = nothing

DigestRS.MoveNext
Loop

' Reset our "LastScheduledRun" variable to the current date
' and time indicating we just did it.
Application.Lock
Application("LastScheduledRun") = Now()
Application.UnLock
End IfThat would be because you are obviously running this on a schedule, next thing yoiu must know is that you should be concatenating a string and not response.write'ing the data to a client.

If i were you i would place this in ascript and schedule windows task scheduler to do this on a timed basis.
 
Back
Top