Closed LOH07 closed 9 months ago
Hello. I have tried to fetch new email messages using an instance of the Mailbox like _instance.get_newmail 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?
Hello. I have tried to fetch new email messages using an instance of the Mailbox like _instance.get_newmail 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
Hello. I have tried to fetch new email messages using an instance of the Mailbox like _instance.get_newmail 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
)
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.
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’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?
And you’re sure new mail messages were received between those two steps?
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?
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?
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
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:
manage.py shell
:
Mailbox
instance and run its get_new_mail
method.manage.py shell
.CTRL+D
-ing to re-enter the exact same bash session.manage.py getmail
from that exact same session.
manage.py shell
session created from this exact same session.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 runninggetmail
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 itsget_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.
Closing since the issue does not seem relevant. @LOH07 Feel free to re-open a new one if needed
Hello. I have tried to fetch new email messages using an instance of the Mailbox like _instance.get_newmail and didn't work. It works if I run:
python3 manage.py getmail
Is this a bug or am I doing something wrong?