Checking mail?

D

Dylan Parry

Hi,

I am by no means a Python programmer, but I am dabbling with it and trying
to create a simple program that reports how many emails I have to
download. So far, using the poplib extension, I have got:

def checkEmail():
email = poplib.POP3('mail.mydomain.ext')
email.user('user')
email.pass_('password')
number = email.stat()
email.quit()

if (number[0] == 0):
return "No new emails"
elif (number[0] == 1):
return "1 new email"
else:
string = str(number[0])
string += " new emails"
return string

Which is fine as long as the server doesn't timeout, or my machine isn't
doing something else that takes up all my bandwidth! Coming from a Java
background, I was wondering if there is anything similar in Python that
allows me to do something like:

try {
something();
}
catch (exception e) {
somethingelse();
}

Where if the "something()" fails then the "somethingelse()" will be ran
instead? Or is there another way that I can deal with timeouts in Python?

Cheers,
 
M

Michal Chruszcz

When I opened my eyes, it was Sat, 10 Jul 2004 12:23:08 +0100.
I said:
try {
something();
}
catch (exception e) {
somethingelse();
}

Where if the "something()" fails then the "somethingelse()" will be ran
instead? Or is there another way that I can deal with timeouts in Python?

I don't know exactly how to deal with pop connections in this case, but
Python has very similar exception handling.

Read more about it at http://docs.python.org/tut/node10.html
 
C

Cameron Laird

.
.
.
numbers = email.list()
count = 0
for n in numbers:
count = count + 1
print "You have", str(count), "new e-mails in inbox."
.
.
.
How's it happen you prefer that to
print "You have %d new e-mails in inbox." % len(email.list())
?
 
D

Dylan Parry

Dylan Parry wrote:

Thanks to all that replied. I have since read the tutorial pointed out,
and it seems to be exactly what I was looking for. Thanks again ;)
 
D

Dag Hansteen

You can do it like this:

def checkEmail():
email = poplib.POP3('mail.mydomain.ext')
email.user('user')
email.pass_('password')
numbers = email.list()
count = 0
for n in numbers:
count = count + 1
print "You have", str(count), "new e-mails in inbox."
email.quit()


Best regards Dag Hansteen




----- Original Message -----
From: "Dylan Parry" <[email protected]>
Newsgroups: comp.lang.python
To: <[email protected]>
Sent: Saturday, July 10, 2004 1:23 PM
Subject: Checking mail?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top