如何安排在django将来某个时间发送的电子邮件? [英] How can I schedule an email to be sent at some point in the future in django?
问题描述
我想安排一个电子邮件发送给用户一个特定的行动。
但是,如果用户采取另一个操作,我想取消该电子邮件并且不发送。
I want to schedule an email to be sent to a user upon a specific action. However, if the user takes another action I want to cancel that email and have it not send.
我将如何在django或python? / p>
How would I do that in django or python?
推荐答案
Beanstalkd
如果您可以安装 beanstalkd 并从命令行运行python脚本我将使用它来安排电子邮件。使用 beanstalkc 客户端,您可以轻松实现此目的。在ubuntu上,您可能需要首先安装:
Beanstalkd
If you can install beanstalkd and run python script from command line I would use that to schedule emails. With beanstalkc client you can easily accomplish this. On ubuntu you might first need to install:
-
sudo apt-get install python-yaml python-setuptools
consumer.py
import beanstalkc
import beanstalkc
def main():
beanstalk = beanstalkc.Connection(host='localhost', port=11300)
while True:
job = beanstalk.reserve()
print job.body
job.delete()
if __name__ == '__main__':
main()
将打印作业5几秒钟后,它被put.py插入。当你想要安排你的电子邮件,但是为了示范的目的,这个事情应该设置得更长。你不想在测试时等待半小时来安排消息;)。
Will print job 5 seconds after it get's inserted by producer.py. Offcourse this should be set longer to when you want to schedule your emails, but for demonstration purposes it will do. You don't want to wait half an hour to schedule message when testing ;).
producer.py:
import beanstalkc
import beanstalkc
def main():
beanstalk = beanstalkc.Connection(host='localhost', port=11300)
jid = beanstalk.put('foo', delay=5)
if __name__ == '__main__':
main()
GAE任务队列
你可以也可以使用 Google App Engine任务队列完成此操作。您可以为 eta = nofollow的>任务。 Google App引擎具有慷慨的免费配额。在任务队列中,webhook使异步请求获取您的URL发送电子邮件的服务器。
GAE Task Queue
You could also use Google App engine task queue to accomplish this. You can specify an eta
for your Task. Google App engine has a generous free quota. In the task queue webhook make Asynchronous Requests to fetch URL on your server which does the sending of emails.
这篇关于如何安排在django将来某个时间发送的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!