Checking mail?
Dag Hansteen
d-hanst at online.no
Sun Jul 11 08:45:25 EDT 2004
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" <usenet at dylanparry.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Saturday, July 10, 2004 1:23 PM
Subject: Checking mail?
> 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,
>
> --
> Dylan Parry
> http://www.webpageworkshop.co.uk - FREE Web tutorials and references
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
More information about the Python-list
mailing list