|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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! |
|
#3
|
|||
|
|||
|
Quote:
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. |
|
#4
|
||||
|
||||
|
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! |
|
#5
|
||||||
|
||||||
|
Quote:
Quote:
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
%>
Quote:
Quote:
|
|
#6
|
|||||
|
|||||
|
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:
|
|
#7
|
||||
|
||||
|
Excellent post!
|
|
#8
|
||||
|
||||
|
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:
Quote:
Code:
oCdoConfg.Fields.Item(strMSSchema & "sendpassword") = "my_password" oCdoConfg.Fields.Item(strMSSchema & "smtpserverport") = 25 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
Hope this message doesn't read like it's from some churlish ungrateful hole-picker, because it's not meant that way. Thanks again. |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > Unable to correctly use scheduled task to open web page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|