Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 600215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:34:55+00:00 2026-05-13T16:34:55+00:00

I use Gmail and an application that notifies me if I’ve received a new

  • 0

I use Gmail and an application that notifies me if I’ve received a new email, containing its title in a tooltip. (GmailNotifier with Miranda-IM) Most of the emails I receive are ones I don’t want to read, and it’s annoying having to login to Gmail on a slow connection just to delete said email. I believe plugin is closed source.

I’ve been (unsuccessfully) trying to write a script that will login and delete the ‘top’ email (the one most recently received). However this is not as easy I thought it would be.

I first tried using imaplib, but discovered that it doesn’t contain any of the methods I hoped it would. It’s a bit like the dbapi spec, containing only minimal functionality incase the imap spec is changed. I then tried reading the imap RFC (rfc3501). Halfway through it, I realized I didn’t want to write an entire mail client, so decided to try using pop3 instead.

poplib is also minimal but seemingly has what I need. However pop3 doesn’t appear to sort the messages in any order I’m familiar with. I have to either call top() or retr() on every single email to read the headers if I want to see the date received.

I could probably iterate through every single message header, searching for the most recent date, but that’s ugly. I want to avoid parsing my entire mailbox if possible. I also don’t want to ‘pop’ the mailbox and download any other messages.

It’s been 6 hours now and I feel no closer to a solution than when I started. Am I overlooking something simple? Is there another library I could try? (I found a ‘chilkat’ one, but it’s bloated to hell, and I was hoping to do this with the standard library)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:34:55+00:00Added an answer on May 13, 2026 at 4:34 pm
    import poplib
    
    #connect to server
    mailserver = poplib.POP3_SSL('pop.gmail.com')
    mailserver.user('recent:YOURUSERNAME') #use 'recent mode'
    mailserver.pass_('YOURPASSWORD') #consider not storing in plaintext!
    
    #newest email has the highest message number
    numMessages = len(mailserver.list()[1])
    
    #confirm this is the right one, can comment these out later
    newestEmail = mailserver.retr(numMessages)
    print newestEmail
    
    #most servers will not delete until you quit
    mailserver.dele(numMessages)
    mailserver.quit()
    

    I worked with the poplib recently, writing a very primitive email client. I tested this with my email server (not gmail) on some test emails and it seemed to work correctly. I would send yourself a few dummy emails to test it out first.

    Caveats:

    • Make sure you are using ‘recent
      mode’:
      http://mail.google.com/support/bin/answer.py?answer=47948
    • Make sure your Gmail account has POP3
      enabled: Gmail > Settings >
      Forwarding and POP/IMAP > “Enable POP
      for all mail”

    Hope this helps, it should be enough to get you going!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a web application that shows users interesting visualizations of their Gmail activity
I'm creating an application that requires passing email addresses around in querystrings and linking
I'm an email n00b but I am working on an application that sends HTML
I'd like to use a C# program to poll a gmail account and automatically
If you type nslookup -type=SRV _xmpp-server._tcp.gmail.com (or use the dig command in OSX) you
In Gmail, I have a bunch of labeled messages. I'd like to use an
Use case: 3rd party application wants to programatically monitor a text file being generated
We use a data acquisition card to take readings from a device that increases
I have to do a Windows application that from times to times access a
I am trying to use gmail's SMTP server smtp.gmail.com to send mails using C

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.