我想安排在执行特定操作时向用户发送电子邮件。
但是,如果用户采取其他操作,我想取消该电子邮件并且不发送它。
我该如何在 django 或 python 中做到这一点?
豆茎
如果可以安装的话豆茎 http://kr.github.com/beanstalkd/并从命令行运行 python 脚本,我将使用它来安排电子邮件。和豆茎c https://github.com/earl/beanstalkc客户您可以轻松完成此任务。在 ubuntu 上,您可能首先需要安装:
-
sudo apt-get install python-yaml python-setuptools
消费者.py:
进口豆茎c
def main():
beanstalk = beanstalkc.Connection(host='localhost', port=11300)
while True:
job = beanstalk.reserve()
print job.body
job.delete()
if __name__ == '__main__':
main()
将在 Producer.py 插入作业后 5 秒打印作业。当然,当您想要安排电子邮件时,应该将其设置得更长,但出于演示目的,它就可以了。测试时您不想等待半个小时来安排消息;)。
生产者.py:
进口豆茎c
def main():
beanstalk = beanstalkc.Connection(host='localhost', port=11300)
jid = beanstalk.put('foo', delay=5)
if __name__ == '__main__':
main()
GAE任务队列
你也可以使用Google App 引擎任务队列 http://code.google.com/appengine/docs/python/taskqueue/overview.html来实现这一目标。您可以指定一个eta
为您Task http://code.google.com/appengine/docs/python/taskqueue/tasks.html#Task。 Google App 引擎有一个慷慨的免费配额 http://code.google.com/appengine/docs/quotas.html#Task_Queue。在任务队列 webhook 中 make异步请求 http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html获取发送电子邮件的服务器上的 URL。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)