3

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=['address@mail.com'])
email.send()

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=['address@mail.com'])
    email.send()

In my settings I have:

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

and finally in the command line I'm running

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.

Any help greatly appreciated

C

Cathal
  • 1,740
  • 18
  • 31
  • I am running into exact same situation. But your answer didn't clarify things. Could you explain in more details? – Philip007 Jul 15 '13 at 00:21

1 Answers1

0

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.

Cathal
  • 1,740
  • 18
  • 31
  • I don't understand your answer. Did you mean after changing `def job` to 'def do' the email gets sent out every minute? – Philip007 Jul 15 '13 at 00:20