本文介绍了创建常规电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是django-cron的新手,我想定期发送邮件。我一直在db shell中运行以下命令:

I am new to django-cron and am trying to send a mail over regular intervals. I've been running the following in the db shell:

from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['[email protected]'])
email.send()

这很好。我在我的一个应用程序中创建了以下cron.py:

which works fine. I've created the following cron.py in one of my apps:

from django_cron import CronJobBase, Schedule
from django.core.mail import EmailMessage

class SendMail(CronJobBase):

    RUN_EVERY_MINS = 1

    schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
    code = 'apps.appname.cron.SendMail'

def job(self):
    email = EmailMessage('Subject', 'Body', to=['[email protected]'])
    email.send()



在我的设置中,我有: / p>

In my settings I have:

CRON_CLASSES = [
    "apps.appname.cron.SendMail",
]

,最后在命令行中运行

env/bin/python manage.py runcrons --settings=settings.dev

我希望这会每分钟发送邮件,但是我没有看到任何命令行错误邮件未发送。

I was hoping that this would send the mail every minute but although I'm not seeing any command line errors the mail isn't being sent.

任何帮助非常感谢

C

推荐答案

旧版本的文档。在SendMail类中,方法应该是'do'而不是'job'。同时邮件只发送一次,而不是每分钟发送一次。

So I think I was looking at an older version of the docs. In the SendMail class the method should be 'do' instead of 'job'. At the same time though the mail is only sending once rather then every minute.

这篇关于创建常规电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:34