Search code examples
pythonmysqlemailreminders

Timed email reminder in python


I have written up a python script that allows a user to input a message, his email and the time and they would like the email sent. This is all stored in a mysql database.

However, how do I get the script to execute on the said time and date? will it require a cron job? I mean say at 2:15 on april 20th, the script will search the database for all times of 2:15, and send out those emails. But what about for emails at 2:16?

I am using a shared hosting provided, so cant have a continously running script.

Thanks


Solution

  • If you cannot have a continuously running script, something must trigger it, so that would have to rely on your OS internals. In a unix environment a cron job, as you self state, would do the trick.

    Set cron to run the script, and make the script wait for a given time and then continue running and sending until the next email is more than this given time away. Then make your script add a new cron job for a new wakeup time.