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 8205483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:15:25+00:00 2026-06-07T08:15:25+00:00

Ok just noticed some weird behavior in my code and just trying to get

  • 0

Ok just noticed some weird behavior in my code and just trying to get to the bottom of the problem. When using the imap library, and trying to check for mail, Do I have to log in each time to see if there is any new mail? For example

#get_mail function.
 def get_mail():
       conn = imaplib.IMAP4_SSL('imap.gmail.com')
       conn.login(gmail_user_id,gmail_user_pass)
       conn.select('inbox')
       conn.search(None,'(Inbox)')
       return something here

Instead could I do something like:

#create 'conn' as a global var
conn = imaplib.IMAP4_SSL('imap.gmail.com')
conn.login(gmail_user_id,gmail_user_pass)
conn.select('inbox')
#get_mail function
def get_mail():
       conn.search(None,'(Inbox)')
       return something here

The problem is that in the second snippet above, if a new mail has been sent AFTER the conn is created, it is not being fetched. So do I have to re-log in every single time the function is run?

  • 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-06-07T08:15:29+00:00Added an answer on June 7, 2026 at 8:15 am

    Do I have to log in each time to see if there is any new mail?

    Yes.

    The problem is that in the second snippet above, if a new mail has
    been sent AFTER the conn is created, it is not being fetched. So do I
    have to re-log in every single time the function is run?

    Normally, you wouldn’t have to login again – you would use IDLE if the IMAP server supports it. IDLE support means you just have to poll for new messages by keeping a connection open (hence “idle”). See this link which describes how to listen for new messages in a loop.

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

Sidebar

Related Questions

I just noticed some weird behaviour with my Android 2.3.3 application. I can write
I'm currently working with a library and noticed something weird when using functions I
This is kind of weird. I'm trying to get my code up on my
I've just noticed that Webkit now has some support regarding the CSS Values and
OK, I realize that question might seem weird, but I just noticed something that
I’m having some difficulties while trying to consume an unmanaged-code dll from my application
I've just started using SyntaxHighlighter . I looked at their HTML source code for
Im having this weird problem with creating Json dynamically.... for some reason this doesnt
I have this really weird problem with my MySQL table. After some time a
I just noticed my code repeats this structure a lot: if( someErrorHappened ){ string

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.