I'm using Django Post Office to send emails in my Django 1.6.2 application but I'm having trouble getting DPO's 'send_queued_mail' command to execute from a crontab file. I want the command to execute every minute. This was my first cron job (owned by the root user):
$ sudo crontab -e
* * * * * . /home/myproj/venv/swing/bin/activate && /home/myproj/venv/myproj/bin/python /www/myproj/manage.py send_queued_mail >> /var/log/send_mail.log 2>&1
When I examine /var/log/syslog, I can see the command and it appears to be executing normally. However, I see this error in the send_mail.log file:
Unknown command: 'send_queued_mail'
Type 'manage.py help' for usage.
It occurred to me that the problem was that since this is root's cronjob, I'm trying to activate a virtual environment for root which does not exist. So I moved the above command to the "myproj" user's crontab (this user owns the project) but I still get the same error.
I also created the following 'send-queued-mail-cronjob' script to execute the command within a virtual environment. This approach has been suggested here on SO to others having the same problem.
#!/bin/sh
cd /home/myproj
source venv/myproj/bin/activate
venv/myproj/bin/python /www/myproj/manage.py send_queued_mail >> /var/log/send_mail.log 2>&1
I call it via this cronjob owned by user 'myproj':
* * * * * /www/myproj/bin/send-queued-mail-cronjob
However, when it runs, I still get the same 'Unknown command error' as before.
Is there something else I need to do? I can execute the commands in the first cronjob from my command line without errors. I can also run the commands in the script from the command line when I log in as user 'myproj' and they run just fine.