在python中定时发送电子邮件提醒 [英] Timed email reminder in python

查看:242
本文介绍了在python中定时发送电子邮件提醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个python脚本,允许用户输入一个消息,他的电子邮件和时间,他们希望发送电子邮件。这都存储在一个mysql数据库中。



但是,如何让脚本在上述时间和日期执行?它需要一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆