This topic is locked

Sample script to send email on timely fashion

7/14/2010 9:14:47 AM
ASPRunnerPro Tips and tricks
J
Jane author

Let's say there is an ExpiryDatefield in the table with events.

To send email if event was expired create new asp file (dailysendmail.asp for example), place this file under generated output directory.

Here is a sample script (for MS Access database):



<!--#include file="include/dbcommon.asp"-->

<%

dalTableName = dal.Table("TableName")

set rstmp = dalTableName.Query("DateDiff('d', Now(), ExpiryDate)>0","")

while not rstmp.eof

'send email for each record

msg = "This event was expired" & vbcrlf

msg = msg & "FieldName1: " & rstmp("FieldName1") & vbcrlf

msg = msg & "FieldName2: " & rstmp("FieldName2") & vbcrlf



set params = CreateObject("Scripting.Dictionary")

params("to")=rstmp("EmailField")

'EmailField is your actual field name

params("subject")="Expired"

params("body")= msg

runner_mail(params)

rstmp.movenext

wend

'FieldName1, FieldName2 and ExpiryDate are your actual field names, TableName is your actual table name

rstmp.close

set rstmp=nothing

%>


To apply this sample for MSSQL database edit SQL query in the following way:

set rstmp = dalTableName.Query("DATEDIFF(day, GETDATE(), ExpiryDate)>0","")



and for MySQL:



set rstmp = dalTableName.Query("DateDiff(now(),ExpiryDate)>0","")


Then use cron to run this script on timely fashion i.e. once a day.

You can use SetCronJobservice to run this script if cron is disabled on your web server:

http://www.setcronjob.com/'>http://www.setcronjob.com/
Here is a step-by-step instruction on how to set up cron job usign SetCronJob:

  1. register on the http://www.setcronjob.com/'>http://www.setcronjob.com/
  2. activate your account and login,
  3. go to Control Panel and click on the 'Create new cron job' link,
  4. fill 'URL to call' with correct URL to your script. For example your generated files are under 'asprunner' directory:

    http://yourhosting.com/asprunner

    So correct URL will be:

    http://yourhosting.com/asprunner/dailysendmail.asp
  5. Save.

S
smireb 5/9/2011

I am trying to use this sample and I am getting an ASP 0245 error. Does anyone know why?

admin 5/9/2011

No, we don't know why you getting this help.
If you need more help post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.