Connecting Tech Pros Worldwide Help | Site Map

How to schedule a email generation task.

Newbie
 
Join Date: Jul 2008
Posts: 30
#1: Jan 28 '09
Hi,

This is an intranet. I wrote an ASP page to display a list of expired tasks. There is a form in this ASP page to send email notification to people who have expried tasks.

Now I want to the email to be automatically generated, by scheduled task or a trigger.

However, I do not know how to do it from here? I was told that I needed to write a script. Please help.
Newbie
 
Join Date: Jul 2008
Posts: 30
#2: Jan 28 '09

re: How to schedule a email generation task.


The ASP script include an emailincl.asp and global.asa.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Jan 28 '09

re: How to schedule a email generation task.


ASP is great for writing tasks that will fire when someone visits a webpage, but to schedule a task they don't work so well. You can use a related scripting technology, Windows Scripts (also using VBScript as the language) to schedule tasks. We have decided to leave those questions in this forum, but I'm not really an expert. Let me think if I can remember which of our users are experts at Windows Scripts.

Jared
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,706
#4: Jan 29 '09

re: How to schedule a email generation task.


I am no expert at Windows Scripting Host work, although I have managed to get a few things to work from time to time.

Let me have a look at this for you and see if I can at least work out a basic outline for you.

I'm afraid I'm not very ASP literate though so I do need to as is this process something that you wish to run as a scheduled task on the server or on the client?

Scheduling is a whole different ball-game of course, but I've done a little work there too so we'll see what can be managed.
Newbie
 
Join Date: Jul 2008
Posts: 30
#5: Jan 29 '09

re: How to schedule a email generation task.


Thanks jhardman and NeoPa.
After some research, I have tried to write the asp into vbscirpt and windows script file. then use Task Scheduler to run the script. However both of them did not work.

file1: testing.vbs
Expand|Select|Wrap|Line Numbers
  1. <!--#include file="emailincl.asp" -->
  2. 'document.write("Hello from VBScript!")
  3. dim counter
  4. counter= 0
  5. dim subject
  6. dim message_text
  7.  
  8. Set conn = CreateObject("ADODB.Connection")
  9. Set rs = CreateObject("ADODB.Recordset")
  10. conn.Open "Driver={SQL Native Client};Server=cslproxy;database=project_management;Trusted_Connection=yes;"
  11.  
  12. sql="select * from task_days when project=7"
  13. rs.open sql, conn 
  14. Do while not rs.eof 
  15. message_text= "This task will be due in the following date"
  16. message_text= message_text & vbcrlf & "Due Date: " & rs("task_due")
  17. message_text= message_text & vbcrlf & "Desctiption: " & rs("description")
  18. message_text= message_text & vbcrlf & "Assign: " & rs("assign")
  19. subject= "Task is due in " & rs("days_left") & " days"
  20.  
  21. email_team rs("project"),subject,message_text
  22. rs.movenext
  23. counter = counter + 1
  24. Loop 
  25. rs.close
  26. conn.close
  27.  

file2: ws_include.wsf
Expand|Select|Wrap|Line Numbers
  1. <job id="includeEmail">
  2.  <script src="emailincl.asp" language="VBScript"/>
  3.   <script language="VBScript">
  4.   dim counter
  5.   counter= 0
  6.  dim subject
  7.  dim message_text
  8.  
  9.   Set conn = CreateObject("ADODB.Connection")
  10.   Set rs = CreateObject("ADODB.Recordset")
  11.   conn.Open  "Driver={SQL Native Client};Server=cslproxy;database=project_management;Trusted_Connection=yes;"
  12.  
  13.    sql="select * from task_days when project=7"
  14.   rs.open sql, conn 
  15.   Do while not rs.eof 
  16.    message_text= "This task will be due in the following date"
  17.    message_text= message_text & vbcrlf & "Due Date: " & rs("task_due")
  18.    message_text= message_text & vbcrlf & "Desctiption: " & rs("description")
  19.    message_text= message_text & vbcrlf & "Assign: " & rs("assign")
  20.    subject= "Task is due in " & rs("days_left") & " days"
  21.  
  22.    email_team rs("project"),subject,message_text
  23.    rs.movenext
  24.    counter = counter + 1
  25.   Loop  
  26.   rs.close
  27.   conn.close
  28.  </script>
  29. </job>
  30.  
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,706
#6: Jan 29 '09

re: How to schedule a email generation task.


OK. Let's see what we can do with this then.

Let's try to be specific and precise though, as otherwise we'll waste lots of time confusing each other.
  1. Let's start with the scheduling.
    When should it be scheduled?
  2. The code.
    You say it doesn't work. What does that mean? What can you tell me about what it does or doesn't do that will take us towards understanding what is going wrong?
You should understand, that from my experience with the WSH (Windows Scripting Host), it is probably the least friendly debugging environment of anything I've seen in many years.

We may well have to write our own debugging info out in the code. It is therefore critically important that we know at all times what we think we know. We will need to focus on particular areas of code at any time so we need to know what of the rest we really can rely on.
Newbie
 
Join Date: Jul 2008
Posts: 30
#7: Jan 30 '09

re: How to schedule a email generation task.


Hi NeoPa,

1. Both are scheduled to run in the next 10minutes to test if it send an email to my and two outlook account. The schedule will stop running if it runs for 10 minutes.

2. I did not receive any emails as I did with the .asp version of the script (which was with form and button)

The following code should call the include file emailincl.asp
Expand|Select|Wrap|Line Numbers
  1. email_team rs("project"),subject,message_text 
  2.  
My working asp file:
Expand|Select|Wrap|Line Numbers
  1. <!--#include file="emailincl.asp" -->
  2. 'html..........etc
  3.  
  4.  
  5. dim counter
  6. counter= 0
  7. dim a
  8.  
  9. 'ADO Connection...........
  10. 'Recordset.....etc
  11. 'Open database.....etc
  12.  
  13. sql="select * from task_days where project=7"
  14.   rs.open sql, conn 
  15.  
  16. 'a= total count of the sql above
  17.  
  18. if request("task")="add" then
  19.  dim subject 
  20.  'need another counter to start from 0
  21.  dim count
  22.  count = 0
  23.  
  24.  Do while count < a
  25.    subject= "Task is due in " & request("days_left_"&count) & " days"
  26.    message_text="This task will be due in the following date: " & request("task_due_"&count)
  27.    message_text=message_text & vbcrlf & "Desctiption: " & request("description_"&count)
  28.    message_text=message_text & vbcrlf & "Assign To: " & request("assign_"&count)
  29.    message_text=message_text & vbcrlf & "Please update the status if this task is completed"
  30.  
  31.    email_team request("project_"&count),subject,message_text
  32.    count = count + 1
  33.  Loop
  34.    response.write vbcrlf & "<br>" & a & "Email submitted."  
  35. else
  36.  
  37.    response.write vbcrlf & "<form action='task_notice2.asp' method='post'>"
  38.    response.write vbcrlf & "<input type=hidden name='task' value='add'>"
  39.  
  40. 'Table header and columns
  41.  
  42.   Do while not rs.eof        
  43.        'Display the recordset from database
  44.    rs.movenext
  45.    counter = counter + 1
  46.   Loop  
  47.     response.write vbcrlf & "</table>"
  48.     response.write vbcrlf & "<input type=submit name=a value='Click'></form>"  
  49.  
  50. rs.close
  51. conn.close
  52. End if
  53.  
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,706
#8: Feb 16 '09

re: How to schedule a email generation task.


I'm sorry Yimma. I don't think I can really help here without spending much more time and effort than I have available.

This appears to be designing a whole (pretty complicated) script from scratch. I can handle some basics, but what you have at the moment is not trivial, but it's not a script either. It's in ASP (which I have no experience in whatsoever). The scheduling job alone, as it is now-relative (not a particular time of day but a time relative to the now of when it's run) is complex enough. I may be able to manage it if tasked with the job, but leading someone else through it at a distance (no way I can test it) would not be practicable.

It is therefore with regret that I must admit that I cannot help you on this one.
Newbie
 
Join Date: Jul 2008
Posts: 30
#9: Feb 17 '09

re: How to schedule a email generation task.


No problems. will do more research.
Reply