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

  • Home
  • SEARCH
  • 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 6916479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:36:30+00:00 2026-05-27T09:36:30+00:00

So I have this class that starts like this: class emailreader(): def __init__(self, server,

  • 0

So I have this class that starts like this:

class emailreader():
    def __init__(self, server, port, username, password):
        self.imap_server = imaplib.IMAP4_SSL(server, int(port))
        self.imap_server.login(username, password)
        self.imap_server.select('INBOX')

    def _get_raw_emails(self):
        messages = []
        typ, data = self.imap_server.search(None, 'UnSeen')
        for num in data[0].split():
            typ, data = self.imap_server.fetch(num, '(RFC822)')
            messages.append(data[0][1])
        return messages

It’s working great for fetching messages like this:

mail = emailreader(server, port, username, password)
emails = mail._get_raw_emails()

But if I send a new message to the e-mail address I can’t just run the last line again, the new mail won’t show up until I delete the mail object and start all over again. Why is that? Do I have to reset the last search or something?

Edit: I think I found the solution. I had to do a imap_server.check() also…

  • 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-27T09:36:30+00:00Added an answer on May 27, 2026 at 9:36 am

    I found the solution. I had to execute a method that’s called check() from my imap object whenever new mails may have arrived. This is my “new” _get_raw_emails() method:

        def _get_raw_emails(self):
            messages = []
            self.imap_server.check() # Fetch new mails since object is created.
            typ, data = self.imap_server.search(None, 'UnSeen')
            for num in data[0].split():
                typ, data = self.imap_server.fetch(num, '(RFC822)')
                messages.append(data[0][1])
            return messages
    

    It may be because I’m not a native english speaker, but when I looked att the documentation for imaplib it did’nt seem obvious what the check method did. It only says “Checkpoint mailbox on server.” So I did’nt thought that it would solve my problem.

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

Sidebar

Related Questions

Assume I have a class that looks like this: class Sample { public string
I have a method that starts like this: public static UnboundTag ResolveTag(Type bindingType, string
I have a few links that look like this: <a href=# class=somelink rotate-90> ...
I have this class that have a function to load other classes and create
I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have this code inside a class that is used by an application and
I have this small class called City that simply holds some information about a
I have a class that contains data from some model. This class has metadata
I have a custom class that implements that IComparable. This class is stored in

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.