Skip to content
Advertisement

imaplib “command SELECT illegal in state NONAUTH” error

I’m attempting to create an application to retrieve and analyse emails sent through gmail. I’m using an alteration on the tutorial found here; http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/

readmail.py

JavaScript

When I run this code through the command line the output is as expected, however when ran through a basic flask import the entire thing falls apart.

app.py

JavaScript

The error I receive is;

JavaScript

I’ve made several attempts this past week to find out ways to fix this error so any help would be appreciated.

Advertisement

Answer

Firstly, looking at the end of the traceback, you’ve got imaplib.error: command SELECT illegal in state NONAUTH, only allowed in states AUTH, SELECTED – and going back to the two lines in the traceback for your code:

JavaScript

I’ve trimmed some excess here, but in test, you are only connecting to the Gmail IMAP server, but not logging in. The following code is what your ffirst file does:

JavaScript

Also, process_mailbox will only return null, it changes the object you’ve passed directly.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement