Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 27th, 2008, 08:26 AM
foreverforever foreverforever is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 128 foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 34 sec
Reputation Power: 236
Unable to correctly use scheduled task to open web page

Hello everybody,

I've set up a script on a web page so that the script sends out emails when the page is visited.

I want to send the emails once per hour, so I think that the best thing (for a newbie like me) to do is set up 24 scheduled tasks (one for every hour of the day, obviously).

I found this thread on ASP Free - http://forums.aspfree.com/asp-development-5/scheduled-task-37383.html?p=104809#post104809 - followed the advice as best I could (see below), but although the scheduled task ran, no emails were sent.

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

Dim objHTTP

Set objHTTP = CreateObject("Msxml2.XMLHTTP")
objHTTP.open "GET", "http://www.mywebsite.com/", false
objHTTP.send
msgbox(objHHTP.ResponseText)

I checked that the web page sends out emails when it is visited - it does.

Can someone please give me some advice with what I need to be doing to get the scheduled task to run correctly?

Reply With Quote
  #2  
Old May 27th, 2008, 12:36 PM
selwonk's Avatar
selwonk selwonk is offline
Contributing User
ASP Free Loyal (3000 - 3499 posts)
 
Join Date: Jun 2004
Posts: 3,020 selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 6 Days 22 h 31 m 19 sec
Reputation Power: 135
When you say it doesn't work, what is the problem? For starters:

msgbox(objHHTP.ResponseText)

...should be...

msgbox(objHTTP.ResponseText)
__________________
selwonk

If I've posted some code above, you might think it looks a bit simplistic. It might be. I'd rather people tried the next step themselves rather than getting a full solution on a plate. That way they learn more!

Reply With Quote
  #3  
Old May 27th, 2008, 01:38 PM
foreverforever foreverforever is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 128 foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 34 sec
Reputation Power: 236
Quote:
Originally Posted by selwonk
When you say it doesn't work, what is the problem? For starters:

msgbox(objHHTP.ResponseText)

...should be...

msgbox(objHTTP.ResponseText)


The scheduled task status displays "Running" but no emails are sent.

The HHTP/HTTP thing was a typo on here, not in the scheduled task, but thanks for bringing it to my attention.

p.s. I don't actually want a message box but as it was in the code that I found, I decided to include it for the moment.

Reply With Quote
  #4  
Old May 27th, 2008, 03:27 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
First things first. You don't need 24 scheduled tasks. One will do. Just repeat the same one every hour.

Second, how can we help when you haven't shown us your script? There's no mail script in any of your posts.

Do you need help will a script you already have or do you need someone to write one for you?

And what are you trying to email?
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Reply With Quote
  #5  
Old May 28th, 2008, 04:51 PM
foreverforever foreverforever is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 128 foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 34 sec
Reputation Power: 236
Quote:
Originally Posted by Nilpo
First things first. You don't need 24 scheduled tasks. One will do. Just repeat the same one every hour.
I'd appreciate it if someone would tell me how to go about setting it to run every hour. I'm using XP and the most frequent schedule looks like once per day to me, but there's obviously more to it.

Quote:
Originally Posted by Nilpo
Second, how can we help when you haven't shown us your script? There's no mail script in any of your posts.
Despite not being asked to do much, it doesn't seem like much of a script to me, but the script (on my PC) with which I'm endeavouring to initiate the email sending process is as follows:
Code:
@LANGUAGE="VBScript"

Dim objHttp

set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

objHttp.open "GET", "http://www.my_domain/email_script.asp", false
objHttp.Send

set objHttp = nothing


The script (on the server) to actually send the emails is as follows:
Code:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/lococon.asp" -->
<%
Dim rs_recipient
Dim rs_recipient_numRows

Set rs_recipient = Server.CreateObject("ADODB.Recordset")
rs_recipient.ActiveConnection = MM_lococon_STRING
rs_recipient.Source = "SELECT email  FROM dom_register  WHERE email_conf='Y' AND deleted='N'"
rs_recipient.CursorType = 0
rs_recipient.CursorLocation = 2
rs_recipient.LockType = 1
rs_recipient.Open()

rs_recipient_numRows = 0
%>
<%

Dim oCdoMsg
Dim oCdoConfg
Dim StrBody
Dim strReferer
Dim strServer
Dim strClientIP
Dim strServerIP
Dim blnSpam

%>
<%

If Not rs_recipient.EOF Then

Do Until rs_recipient.EOF

set oCdoMsg = server.createobject("CDO.Message")

oCdoMsg.to = (rs_recipient.Fields.Item("email").Value)
        oCdoMsg.from = "service@my_domain.com"
        oCdoMsg.Subject = "Test Message"

		strBody = strBody & "This message was sent as a result of a scheduled task coming into operation." & vbcrlf & vbcrlf
		strBody = strBody & " - - - - - - - - - -" & vbcrlf & vbcrlf
		strBody = strBody & "Thank you," & vbcrlf & vbcrlf
		oCdoMsg.Textbody = strBody
        oCdoMsg.Textbody = oCdoMsg.Textbody


strMSSchema = "http://schemas.microsoft.com/cdo/configuration/"
        Set oCdoConfg = Server.CreateObject("CDO.Configuration")
        oCdoConfg.Fields.Item(strMSSchema & "sendusing") = 2
        oCdoConfg.Fields.Item(strMSSchema & "smtpserver") = "smtp.my_domain.com"
        oCdoConfg.Fields.Update 
        Set oCdoMsg.Configuration = oCdoConfg
	  
	    oCdoMsg.send
		rs_recipient.movenext
Loop
		Response.Redirect("home.asp")
         
End If
		 
%>
<%
set oCdoMsg = nothing
set oCdoConfg = nothing
%>
<%
rs_recipient.Close()
Set rs_recipient = Nothing
%>
It works, although obviously I've changed the domain & database details.

Quote:
Do you need help will a script you already have or do you need someone to write one for you?
I need someone to tell me what I need to do to make the scheduled task initiate the sending of the emails.

Quote:
And what are you trying to email?
A test message.

Reply With Quote
  #6  
Old May 28th, 2008, 05:34 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
First off, there's no need for ASP here. It's the wrong tool for the job, so let's stick to VBScript alone. You'll need to grab your connection string from lococonn.asp, but here's the code:
vb Code:
Original - vb Code
  1. Set rs_recipient = Wscript.CreateObject("ADODB.Recordset")
  2. rs_recipient.ActiveConnection = MM_lococon_STRING
  3. rs_recipient.Source = "SELECT email  FROM dom_register  WHERE email_conf='Y' AND deleted='N'"
  4. rs_recipient.CursorType = 0
  5. rs_recipient.CursorLocation = 2
  6. rs_recipient.LockType = 1
  7. rs_recipient.Open()
  8.  
  9. rs_recipient_numRows = 0
  10.  
  11. If Not rs_recipient.EOF Then
  12.     Do Until rs_recipient.EOF
  13.         set oCdoMsg = Wscript.createobject("CDO.Message")
  14.         oCdoMsg.to = (rs_recipient.Fields.Item("email").Value)
  15.         oCdoMsg.from = "service@my_domain.com"
  16.         oCdoMsg.Subject = "Test Message"
  17.  
  18.         strBody = strBody & "This message was sent as a result of a scheduled task coming into operation." & vbcrlf & vbcrlf
  19.         strBody = strBody & " - - - - - - - - - -" & vbcrlf & vbcrlf
  20.         strBody = strBody & "Thank you," & vbcrlf & vbcrlf
  21.         oCdoMsg.Textbody = strBody
  22.         oCdoMsg.Textbody = oCdoMsg.Textbody
  23.  
  24.         strMSSchema = "http://schemas.microsoft.com/cdo/configuration/"
  25.         Set oCdoConfg = Wscript.CreateObject("CDO.Configuration")
  26.         oCdoConfg.Fields.Item(strMSSchema & "sendusing") = 2
  27.         oCdoConfg.Fields.Item(strMSSchema & "smtpserver") = "smtp.my_domain.com"
  28.         oCdoConfg.Fields.Update
  29.         Set oCdoMsg.Configuration = oCdoConfg
  30.       
  31.         oCdoMsg.send
  32.         rs_recipient.movenext
  33.     Loop
  34. End If
  35.         
  36. rs_recipient.Close()
Name that with a .vbs extension and file it away in a directory somewhere. Now let's create your Scheduled Task.
  1. Open the Scheduled Tasks folder by click Start and selecting Control Panel > Performance and Maintenance > Scheduled Tasks.
  2. Now double-click Add Scheduled Task to start the Scheduled Task Wizard.
  3. Click the Next button.
  4. Click Browse... and locate the VBS file you just created.
  5. Select Daily from the radio list and click Next.
  6. Set your start time (i.e. 12:01 AM) and select Every Day from the radio list. Click the Next button.
  7. Enter the user name and password of a user with the necessary credentials and click Next.
  8. Select Open advanced properties for this task when I click Finish and click the Finish button. (You may receive an error about the script name you've provided...just ignore it.)
  9. You should have the Advanced Properties dialog open. On the Task tab, edit the Run text box with the correct command line to run. It should be cscript.exe C:\myfolder\myscript.vbs. Be sure to include the full path to your script. If it contains spaces, make sure to enclose the path in quotes.
  10. Select the Schedule tab and click the Advanced... button.
  11. Select the Repeat task checkbox.
  12. Select every (1) hours and set the duration to 1 hour and 1 minute.
  13. Click OK and Apply to close all dialogs.
You're all set. Instead of waiting until 12:01 AM, you can kick of your scheduled task manually and test it. Right-click it in the Scheduled Tasks window and choose Run.
Comments on this post
selwonk agrees!
foreverforever agrees: If I'd explained properly, the solution would've been perfect!

Reply With Quote
  #7  
Old May 28th, 2008, 05:39 PM
selwonk's Avatar
selwonk selwonk is offline
Contributing User
ASP Free Loyal (3000 - 3499 posts)
 
Join Date: Jun 2004
Posts: 3,020 selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level)selwonk User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 6 Days 22 h 31 m 19 sec
Reputation Power: 135
Excellent post!
Comments on this post
Nilpo agrees: Thank you.

Reply With Quote
  #8  
Old May 29th, 2008, 08:06 AM
foreverforever foreverforever is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 128 foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level)foreverforever User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 34 sec
Reputation Power: 236
Thanks Nilpo, but it isn't really what I was asking. I probably didn't explain properly that what I really wanted was to get a scheduled task on my PC that would initiate the sending of emails by my server, whereas you've kindly sorted out my script to send emails from my PC.

The reason that I wanted to send the emails via the server rather than the PC is that I expect that there will be occasions when many hundreds of emails will be sent and I want to avoid all possibilities of throttling/anti-spam systems by my broadband provider stopping the flow of emails - incidentally, the emails won't be spam, just in case you're wondering; they'll all be event-related "opt-in" emails.

Incidentally, as other people may want to use the script, I should mention that in order to get it to work I added two lines to your code. Not sure how important they are in all scenarios, but I needed them. Between;
Quote:
oCdoConfg.Fields.Item(strMSSchema & "smtpserver") = "smtp.my_domain.com"
and;
Quote:
oCdoConfg.Fields.Update
I added;
Code:
		oCdoConfg.Fields.Item(strMSSchema & "sendpassword") = "my_password"
		oCdoConfg.Fields.Item(strMSSchema & "smtpserverport") = 25
I also found that "cscript.exe" in the Advanced/Task/Run prevented it from running for some reason.

But it's not all doom & gloom because you sent me the right way for what I was after: how to send the emails every hour, and how to sort out the script on my PC to initiate the sending of emails by my server. Again, as other people may benefit from it, the code for the script on my PC (to initiate the sending of the emails by my server) is now;
Code:
Dim objHttp

set objHttp = CreateObject("Msxml2.ServerXMLHTTP")

objHttp.open "GET", "http://www.my_domain.com/email_script.asp", false
objHttp.Send

set objHttp = nothing
So that's my scheduled task/email sending problem sorted out.

Hope this message doesn't read like it's from some churlish ungrateful hole-picker, because it's not meant that way.

Thanks again.

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > Unable to correctly use scheduled task to open web page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off