1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP scheduled emailer not working...

Discussion in 'C#' started by sudoku, Jul 8, 2006.

  1. #1
    Here's what I wanted to do: set up a "puzzle of the day" email delivery system that people could subscribe to.

    Here's how I attempted it: using a modified version of an article on asp101 (getting scripts to run on a schedule), I put the following code at the bottom of my site's homepage:
    <%
    If DateDiff("d", Application("LastScheduledRun"), Now()) > 0 Then
         Application.Lock
        Application("LastScheduledRun") = Now()
        Application.UnLock
        'Trigger the emailer, which will then redirect back to here.
        Response.Redirect "/delivery.asp"
    End If
    %>
    Code (markup):
    delivery.asp in turn sends off that day's puzzle and redirects back to the homepage.

    Well, it worked, sort of. I had my own email as the only recipient for the past 4 days as a test. And I did indeed get the puzzles: 3 times a day. That's problem number 1.

    Until today, when I didn't get the puzzle at all. By this time of day, it's usually arrived twice. That's problem number 2.

    Any suggestions? Up to and definitely including "try the following free service/script instead"... :)

    Note that this is a godaddy hosted, cheap-as-possible account. I don't believe I can access any kind of scheduled task controller on the server.

    Thanks in advance.
     
    sudoku, Jul 8, 2006 IP
  2. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #2
    could you please post the script that you use to send the emails.

    also you need to configure the datetime before writing this line of code

    "DateDiff("d", Application("LastScheduledRun"), Now()) > 0"

    Take care of the DATE first of all, then you'll get what you long for.
     
    ludwig, Jul 10, 2006 IP
  3. jaymcc

    jaymcc Peon

    Messages:
    139
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The other thing to remember is that your application variables only stay 'alive' until your application is reset. This happens from time to time, especially on a shared server where you might be subject to the IIS server recycling your application pool (for any number of reasons). I think every time you edit your global.asa file you might be resetting your application also.

    The reason this is important is that if your relying on the application variable, and your application is restarted, then you will get multiple messages in a day. You might be better off storing some of this information (like the last run date) in a database.

    In relation to getting nothing then you might want to check that someone is actually hitting the home page on those days, otherwise you'll get zip!

    I had this running on our site a while back, at midnight it would send out a bunch of messages based on different things.

    I used the following code in my session_onstart section of my global.asa file. This assumes of course that the DB existed and had a table called tblLog with the right fields yada yada.

    	dim Con, rsLog
    	set Con = server.CreateObject("ADODB.Connection")
    	Con.Open Application("DBConnection")
    	set rsLog = Con.Execute("SELECT LastDate FROM tblLog WHERE Date() = LastDate")
    	If rsLog.EOF Then
    		Con.Execute "UPDATE tblLog SET LastDate = Date()"
    		Call DailyTasks
    	End If
    	rsLog.close
    	con.close
    	set rsLog = Nothing
    	set Con = Nothing
    Code (markup):

    Hope this helps, you might want to setup a scheduled service on your own computer that 'hits' a specific page at intervals to trigger this, but that relies on your computer being turned on i guess. There is a tool from smarttools.com that pings pages at specified images, it's free.

    Jay
     
    jaymcc, Jul 10, 2006 IP
  4. sudoku

    sudoku Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Jay, that's quite helpful! It makes sense of the weird pattern of the timing as well -- I'd be getting one from the initial visit after midnight, then one for the initial visit after each of the twice-daily backups. At least I assume they're twice-daily backups... And the "gap" in the thrice daily would make sense as my visits/day plummets on the weekends.

    I'll experiment with adding a "last run date" variable. Seems like you could add that in a included txt file, same as you would use for a simple page hit counter.
     
    sudoku, Jul 12, 2006 IP
  5. sudoku

    sudoku Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    For the sake of historical interest (if anyone has that): what I ended up doing was to add an "If Hour(Now()) < 8 Then" to the emailer page. Now, if the main page redirects someone to the mailer page based on the server being backed up (or whatever), all the mailer page does is redirect them to the main page again.

    Thanks again to ludwig and jaymcc for your suggestions.
     
    sudoku, Jul 21, 2006 IP