473,698 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

gmail/poplib: quickly detecting new mail

LJ
Hello,

I'm trying to monitor my gmail account to know when I have obtained a
new email. It seems that once I have logged in, I should be able to
call the stat() function repeatedly to see how many messages are in my
inbox. The problem is that this number does not seem to update until I
have logged out, and logged back in. In other words, I run the code
below, send myself an email, and observe that the count does not
change. If I kill the program and restart (hence logging back in),
then the total count is now updated. The other function calls seem to
work the same way (eg "list" just shows the same list, even when I know
new mail has arrived).

Questions:
1. is this a standard behavior of pop protocol? (to give me the same
results for any API call on a single login?)
2. OR is this a peculiarity of gmail
3. is there a more efficient and correct way to see know when I have
received a new mail? Currently my "working" method is to log out and
log back in. With this method, I can get about 17 refreshes per minute
but anything faster and Gmail blocks me for a few minutes. (yes it is
important to my application that I have very frequent refreshes).

(see code sample below)

Thanks,
LJ

---

import poplib
import time
from email.Parser import Parser

parser = Parser()
server = poplib.POP3_SSL ("pop.gmail.com ", 995)
print server.user("XX X-MY_EMAIL")
print server.pass_("X XX-MY_PW")
server.set_debu glevel(0)

def getMsgCount():
# check message count by stat() and list() functions
numMsgs = server.stat()[0]
print "Num msg by stat():", numMsgs
print "Num msg by list():", len(server.list ()[1])
print "Most recent:", numMsgs, getSubj(numMsgs )
return

def getSubj(which):
# return subject of message with id 'which'
msg = "\n".join(serve r.top(which, 1)[1])
email = parser.parsestr (msg)
return email.get("Subj ect")

while True:
print "--"
getMsgCount()
time.sleep(2)

Jul 1 '06 #1
1 8160
LJ <lj****@gmail.c om> wrote:
...
1. is this a standard behavior of pop protocol? (to give me the same
results for any API call on a single login?)
2. OR is this a peculiarity of gmail


Definitely POP3 standard behavior, as a simple reading of the relevant
RFC will show (e.g., http://www.ietf.org/rfc/rfc1939.txt):
summarizing... on entering Transaction state, a POP3 server acquires an
exclusive lock on the mailbox, to ensure that no modifications occur to
it throughout the session.

I'm not sure about the refresh frequency, but you may want to try the
Atom feed, https://mail.google.com/gmail/feed/atom .
Alex
Jul 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2987
by: Simon Burton | last post by:
This was so easy :) Simon Burton. #!/usr/bin/env python import sys from time import sleep from poplib import *
2
6722
by: brettk | last post by:
Hello All, Here's what I'm trying to do: I need to connect to a pop3 server, download all messages, and copy all of the attachments into a specific directory. The actual email message is unimportant. Now, I've found plenty of examples that strip the attachments from an email message, but most (if not all) of them take a file parameter. My question is this:
2
2690
by: Steve Greenland | last post by:
For the poplib.POP3 object, docs say: list() Request message list, result is in the form (response, ). If which is set, it is the message to list. But (I've folded the long line): Python 2.3.5 (#2, May 4 2005, 08:51:39) on linux2
1
1606
by: Alessandro Bottoni | last post by:
Is there any module or interface that allow the programmer to access a imap4/pop3 server in a more pythonic (or Object Oriented) way than the usual imaplib and popolib? I mean: is there any module that would allow me to query the server for specific messages (and fetch them) in a way similar to a OODB? TIA -----------------------------------
0
1220
by: Frank Churchill | last post by:
Has anyone used poplib and popfile together? I've tried everything I can think of to specify SRVR in poplib: "127.0.0.1:8081" "127.0.0.1,port=8081" "localhost:8081" "localhost,port=8081" and probably a few other things, but poplib can't see
5
2099
by: Gregory Piero | last post by:
I was wondering what methods you experts would reccomend for this task? Here are the options I have come up with so far: 1. Build something with the poblib library (http://docs.python.org/lib/module-poplib.html) --Any pointers on doing this? How to I get poplib to save messages in a standard format I can later import into Thunderbird, Outlook, etc? (mbox?)
0
1130
by: 叮叮当当 | last post by:
Hi, all. i have two question with poplib: 1. How to judge if a mail is or not a new mail ? 2. How Can i get the send-mailbox's mail? thanks .
3
6091
by: EuGeNe Van den Bulke | last post by:
Hi there, I am trying to use the poplib library to get emails using the retr method. The small program bellow works but the message aren't flagged as read which puzzles me. I believe the pop server is qmail 1.0.6 / vpopmail 5.2.1 and I am running the following script on Windows using Pyhton 2.5. import poplib import email
4
4760
by: Jean-Claude Neveu | last post by:
Hello, I am writing a Python program to check email using POP3. I've tried the sample code from python.org, and it works great. In other words, the code below successfully prints out my emails. import getpass, poplib, email M = poplib.POP3('mail.blah.com') M.user('username') M.pass_('password')
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.