Sending a lockfile to django-post_office send_queued_mail

816 views Asked by At

This doesn't seem like it should be hard, but I'm stumped. I've gotten django-post_office integrated with my codebase, and now I'm trying to test that I can set up cron jobs for queued email as described in the docs:

https://github.com/ui/django-post_office

Whether I run on the command line or in crontab, I get the same problem:

python manage.py send_queued_mail lockfile='/home/gbeadmin/tmp/post_office.lock'
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/gbeadmin/.local/lib/python2.7/site-packages/post_office/management/commands/send_queued_mail.py", line 33, in handle
    options['lockfile'])
KeyError: 'lockfile'

Digging around, I see that I should be able to specify the lockfile, so I've tried:

python manage.py send_queued_mail --lockfile='<path to lock file>'

Which then gives me the error:

Usage: manage.py send_queued_mail [options] 

manage.py: error: no such option: --lockfile

I've also tried the '-L' option listed in the docs, with the same basic result.

I'm lost - I don't see a bug in my syntax, I don't see any other way to set the lock file...

Other notes:

  • I'm running in WebFactional
  • I'm running django 1.6 (yes, I want to upgrade, that is on the way but can't be in the scope for this ticket)
  • django-post_office - 2.0.8
  • python 2.7
3

There are 3 answers

1
Fendy Heryanto Johan On

I'm sorry to hear your problem, but the problem is located in the management command. You see, the KeyError means the 'lockfile' does not exist in the dictionary. Further investigation yields that the root cause of the problem is in the management command. The management command syntax is valid only for Django 1.8 and up. They're currently dropping support for Django < 1.8. Hope this helps !

0
oruchkin On

Short answer that helped me:

reload your computer

With details:

I encountered same error while trying to send emails with send_queued_mail command. But previous to it i changed my settings and this library froze. I tried to reload project but only reloading my computer helped, i encountered this error twice, and reloading computer solved problem.

0
Gaurav Saluja On

I had the same issue using django-post-office. Downgrading to versions (1.1.2, 1.1.0, 1.0.0) also didn't help.

FYI, I was using Python 2.7.7 and Django version (1, 4, 2, 'final', 0)

I tried django-mailer instead. Link Here and it worked like a charm. Followed the same steps used with django-post-office.

pip install django-mailer

Added the following to my settings.py file

INSTALLED_APPS = [
    ...
    "mailer",
    ...
]

EMAIL_BACKEND = "mailer.backend.DbBackend"

After, I ran this command

python manage.py syncdb

It created the following tables:

Creating table mailer_message

Creating table mailer_dontsendentry

Creating table mailer_messagelog

No change is further required in your code.

After i sent some mails in my application, they were added to the db table mailer_message

To send those emails, i used the management command added by django-mailer

python manage.py send_mail

After the messages were sent, they were removed from the db table and added to the logs table - mailer_messagelog instead. You could create a cron job to run this command after a given interval of time.

Hope this helps.