在python中定时发送电子邮件提醒 [英] Timed email reminder in python
问题描述
但是,如何让脚本在上述时间和日期执行?它需要一个cron工作吗?我的意思是说在2月20日2点15分,脚本将在数据库中搜索2:15的所有时间,并发送这些电子邮件。但是在2:16的电子邮件呢?
我正在使用提供的共享主机,所以不能有一个持续运行的脚本。
谢谢
如果您不能持续运行脚本,则必须触发它,依靠您的操作系统内部。在一个unix环境中,一个cron工作,像你自己的状态一样,会做这个伎俩。
设置cron来运行脚本,使脚本等待给定的时间,然后继续运行和发送,直到下一封电子邮件超过此给定的时间。然后让您的脚本添加一个新的cron工作,以获得新的唤醒时间。
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
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.
这篇关于在python中定时发送电子邮件提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!