Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable push-notification for IMAP (Gmail) using Python imaplib?

Tags:

python

gmail

imap

Is there a way to monitor a gmail account using imaplib without polling gmail each time I want to see if there is new mail. Or in other words, I just want the script to be notified of a new message so I can process it right away instead of any lag time between polls.

I see that the IMAP protocol supports this with the IDLE command, but I can't see anything documented with it in the imaplib docs, so any help with this would be great!

like image 401
RaySl Avatar asked Sep 07 '25 14:09

RaySl


2 Answers

There isn't something in imaplib that does this, AFAIK (disclamer: I know very little about Python), however, it seems that someone has implemented an IDLE extension for Python which has the same interface as imaplib (which you can swap out with no changes to existing code, apparently):

https://github.com/imaplib2/imaplib2

like image 80
casperOne Avatar answered Sep 10 '25 07:09

casperOne


Check out ProcImap. It's a more abstract framework on top of libimap and libimap2, providing a nice solution to handle IMAP services. Looks like just the stuff you are looking for, and for me as well. I'm right having the same problem with you and just found ProcImap. Gonna try it for myself.

like image 26
evo Avatar answered Sep 10 '25 06:09

evo