Code Monkey home page Code Monkey logo

Comments (13)

Pietro395 avatar Pietro395 commented on July 28, 2024

Hello. I have tried to fetch new email messages using an instance of the Mailbox like instance.get_new_mail and didn't work. It works if I run: python3 manage.py getmail Is this a bug or am I doing something wrong?

Hi @LOH07,
What type of mailbox are you using?

from django-mailbox.

LOH07 avatar LOH07 commented on July 28, 2024

Hello. I have tried to fetch new email messages using an instance of the Mailbox like instance.get_new_mail and didn't work. It works if I run: python3 manage.py getmail Is this a bug or am I doing something wrong?

Hi @LOH07, What type of mailbox are you using?

imap on localhost
It does work if I use
python3 manage.py getmail but I want to fetch for a specific mailbox instance
It is very confusing because I don't get absolutely any error message

from django-mailbox.

Pietro395 avatar Pietro395 commented on July 28, 2024

Hello. I have tried to fetch new email messages using an instance of the Mailbox like instance.get_new_mail and didn't work. It works if I run: python3 manage.py getmail Is this a bug or am I doing something wrong?

Hi @LOH07, What type of mailbox are you using?

imap on localhost It does work if I use python3 manage.py getmail but I want to fetch for a specific mailbox instance It is very confusing because I don't get absolutely any error message

It should work, here it is the code of manage.py getmail:

    @staticmethod
    def get_new_mail_all_mailboxes(args=None):
        mailboxes = Mailbox.active_mailboxes.all()
        if args:
            mailboxes = mailboxes.filter(
                name=' '.join(args)
            )
        for mailbox in mailboxes:
            logger.info(
                'Gathering messages for %s',
                mailbox.name
            )
            messages = mailbox.get_new_mail()
            for message in messages:
                logger.info(
                    'Received %s (from %s)',
                    message.subject,
                    message.from_address
                )

from django-mailbox.

LOH07 avatar LOH07 commented on July 28, 2024

Have you tried:
from django_mailbox.models import Mailbox,Message
mboxes = Mailbox.objects.all()

and then:
mboxes[0].get_new_mail();

It definitely doesn't work.
There already is an active mailbox in my database.

What frustrates me even more is the lack of any error message. Absolutely nada.

from django-mailbox.

coddingtonbear avatar coddingtonbear commented on July 28, 2024

I’m afraid we’d need more information to know how to help you. Could you elaborate on what isn’t working for you, or give us a traceback?

from django-mailbox.

LOH07 avatar LOH07 commented on July 28, 2024

I’m afraid we’d need more information to know how to help you. Could you elaborate on what isn’t working for you, or give us a traceback?

I have installed Dovecot and Postfix on my computer and they are running ok.
Then I installed django-mailbox via pip.
I created a Django app (just for testing purposes) and ran python3 manage.py migrate in order to create the tables for django_postfix and then ran python3 manage.py getmail. The database got populated with mailboxes and messages from Postfix. No problem so far but then whenever I go to the shell with python3 manage.py shell and try to get new messages from Postfix with instance_of_Mailbox.get_new_mail; nothing happens. The database doesn't get updated and there is no error message either.
Is it clear now?

from django-mailbox.

coddingtonbear avatar coddingtonbear commented on July 28, 2024

And you’re sure new mail messages were received between those two steps?

from django-mailbox.

LOH07 avatar LOH07 commented on July 28, 2024

And you’re sure new mail messages were received between those two steps?

python3 manage.py getmail outside the django shell works. All messages are retrieved from Postfix. I can see in the database.

instance_of_Mailbox.get_new_mail; doesn't work anywhere. Neither in django shell, nor in views.py

How can I collect more info to help you debug?

from django-mailbox.

coddingtonbear avatar coddingtonbear commented on July 28, 2024

I’m really going to need more information about what “not works” means, and can’t help but notice that my question above was not answered. Are you certain that there were new messages to retrieve?

from django-mailbox.

LOH07 avatar LOH07 commented on July 28, 2024

I’m really going to need more information about what “not works” means, and can’t help but notice that my question above was not answered. Are you certain that there were new messages to retrieve?

Yes, there are new messages to retrieve. This is the output in terminal when I run mail -u liviu:

liviu@localhost:~$ mail -u liviu
"/var/mail/liviu": 2 messages 1 unread
1 Mail System Intern Sun Apr 30 15:41 13/520 DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
>U 2 liviu@localhost Sun Apr 30 17:08 16/433 Test msg
Held 2 messages in /var/mail/liviu

and this is the output to python3 manage.py getmail:

liviu@localhost:~/DJANGO/EmailClient$ python3 manage.py getmail
INFO:django_mailbox.management.commands.getmail:Gathering messages for liviu
INFO:django_mailbox.management.commands.getmail:Received Test msg (from ['liviu@localhost'])

This works

from django-mailbox.

coddingtonbear avatar coddingtonbear commented on July 28, 2024

I'd be suspicious that when running getmail vs. running the method directly that you're maybe interacting with different databases or something like that. Maybe, for example, when you're running getmail from a shell, you're in a shell that isn't using the correct django configuration 🤷 They're invoking exactly the same code and I use this in production actively; so I can't imagine how this could be anything other than an environment problem.

For setting up a minimal pair of working/not-working to try this -- I suppose you could try:

  • Opening bash or whatever.
  • Send a test message to the relevant e-mail mailbox.
  • Running manage.py shell:
    • Find the relevant Mailbox instance and run its get_new_mail method.
    • Verify that new mail was not received by running a query from this manage.py shell.
    • CTRL+D-ing to re-enter the exact same bash session.
  • Running manage.py getmail from that exact same session.
    • Verify that new mail was received by runniong a query from a manage.py shell session created from this exact same session.

from django-mailbox.

LOH07 avatar LOH07 commented on July 28, 2024

I'd be suspicious that when running getmail vs. running the method directly that you're maybe interacting with different databases or something like that. Maybe, for example, when you're running getmail from a shell, you're in a shell that isn't using the correct django configuration shrug They're invoking exactly the same code and I use this in production actively; so I can't imagine how this could be anything other than an environment problem.

For setting up a minimal pair of working/not-working to try this -- I suppose you could try:

  • Opening bash or whatever.

  • Send a test message to the relevant e-mail mailbox.

  • Running manage.py shell:

    • Find the relevant Mailbox instance and run its get_new_mail method.
    • Verify that new mail was not received by running a query from this manage.py shell.
    • CTRL+D-ing to re-enter the exact same bash session.
  • Running manage.py getmail from that exact same session.

    • Verify that new mail was received by runniong a query from a manage.py shell session created from this exact same session.

That's exactly what I did.
But you are probably right that it must be an environment configuration issue.
Thanks for assistance.

from django-mailbox.

pfouque avatar pfouque commented on July 28, 2024

Closing since the issue does not seem relevant.
@LOH07 Feel free to re-open a new one if needed

from django-mailbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.