Checking mail?

Discussion in 'Python' started by Dylan Parry, Jul 10, 2004.

  1. Dylan Parry

    Dylan Parry Guest

    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
    Dylan Parry, Jul 10, 2004
    #1
    1. Advertising

  2. When I opened my eyes, it was Sat, 10 Jul 2004 12:23:08 +0100.
    I couldn`t believe that Dylan Parry wrote:
    > 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

    --
    ____________________________________________________________________
    -=- Michal Chruszcz -=- Seen at http://prox.pl/~troll/?gallery -=-
    To follow the path: look to the master, follow the master,
    walk with the master, see through the master, become the master.
    Michal Chruszcz, Jul 10, 2004
    #2
    1. Advertising

  3. Dylan Parry

    Chris Share Guest

    On Sat, 10 Jul 2004 12:23:08 +0100, Dylan Parry <> wrote:
    > try {
    > something();
    > }
    > catch (exception e) {
    > somethingelse();
    > }


    I suggest you read http://www.python.org/doc/current/tut/node10.html,
    and the rest of the tutorial too.

    In short:

    try:
    code
    goes
    here
    except FooError:
    foofix()

    chris
    Chris Share, Jul 10, 2004
    #3
  4. In article <>,
    Dag Hansteen <> wrote:
    .
    .
    .
    > 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())
    ?
    Cameron Laird, Jul 10, 2004
    #4
  5. Dylan Parry

    Dylan Parry Guest

    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 ;)

    --
    Dylan Parry
    http://www.webpageworkshop.co.uk - FREE Web tutorials and references
    Dylan Parry, Jul 10, 2004
    #5
  6. Dylan Parry

    Dag Hansteen Guest

    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" <>
    Newsgroups: comp.lang.python
    To: <>
    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
    >
    >
    Dag Hansteen, Jul 11, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Curt_C [MVP]
    Replies:
    5
    Views:
    354
    Karim
    May 19, 2004
  2. me
    Replies:
    0
    Views:
    430
  3. > Adrian

    Checking outgoing mail

    > Adrian, Jan 26, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    293
    Peter Bradley
    Feb 1, 2007
  4. Nex_s

    FTP error checking- call e-mail sub

    Nex_s, Aug 4, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    73
    Nex_s
    Aug 4, 2005
  5. Nex_s

    FTP error checking- call e-mail sub

    Nex_s, Aug 4, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    100
    Dave Weaver
    Aug 8, 2005
Loading...

Share This Page