coddingtonbear / django-mailbox

Import mail from POP3, IMAP, local email mailboxes or directly from Postfix or Exim4 into your Django application automatically.
MIT License
357 stars 166 forks source link

message_received signal not firing? #233

Closed joshuakoh1 closed 4 years ago

joshuakoh1 commented 4 years ago

/base/myapp/init.py

default_app_config = 'myapp.apps.MyAppConfig'

/base/myapp/apps.py

from django.apps import AppConfig
class MyAppConfig(AppConfig):
    name = 'myapp'
    def ready(self):
        import myapp.signals

/base/myapp/signals.py

from django_mailbox.signals import message_received
from django.dispatch import receiver
@receiver(message_received)
def handle_new_email(sender, message, **args):
    print('Recieved a message titled %s from a mailbox named %s' % (message.subject, message.mailbox.name, ))
    otherfunction(sender, message, **args)
    print('Done')

/base/settings.py

INSTALLED_APPS = [
    'myapp',
]
ad-m commented 4 years ago

Are you running getmail command?

joshuakoh1 commented 4 years ago

The mail was being added to the DB but the signal wasn't firing.

Funny story. Spent many hours breaking stuff trying to make it work. Went for a walk and had a crazy idea.

Under installed apps, I had myapp under django_mailbox. Switched it around myapp first and django_mailbox below and it's working now. Signals frustrate me so much.

abratchik commented 3 months ago

I have a similar problem - message_received is not firing when I'm receiving emails using getmail. I trigger 'manage getmail' using cron job every minute. Emails are appearing in the admin view but no signals are fired. Swapping applications around in the installed apps did not help.