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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:53:21+00:00 2026-05-27T21:53:21+00:00

I would like to log into my account with Python and get python to

  • 0

I would like to log into my account with Python and get python to print the messages I received in my mailbox. I know how to connect

import getpass, poplib
user = 'my_user_name' 
Mailbox = poplib.POP3_SSL('pop.googlemail.com', '995') 
Mailbox.user(user) 
Mailbox.pass_('my_password') 

I don’t know how to get Python to display my messages. I tried all the functions in the poplib doc. They only display numbers.

  • 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-27T21:53:21+00:00Added an answer on May 27, 2026 at 9:53 pm

    You have not posted your source code, but here is my response:

    How to get the total number of messages:

    (numMsgs, totalSize) = self.conn_pop3.stat()
    

    How to get a specific message, knowing its number in the mailbox:

    (server_msg, body, octets) = self.conn_pop3.retr(number)
    

    So the function you might need is retr, it returns a tuple.
    See
    here.

    Careful it also sets the respective email as SEEN on the server!
    You can probably undo that, at least with IMAP you can.

    And my implementation of a pop3 lib email read:

    from poplib  import POP3
    ...
        if self.pop3_connected:            
            try:
                #------Check if email number is valid----------------------
                (numMsgs, totalSize) = self.conn_pop3.stat()
                self.debug(200, "Total number of server messages:    ", numMsgs)                
                self.debug(200, "Total size   of server messages:    ", totalSize)
                if  number>numMsgs:
                    self.debug(200, "\nSorry - there aren't that many messages in your inbox\n")
                    return False
                else:
                    (server_msg, body, octets) = self.conn_pop3.retr(number)
                    self.debug(200, "Server Message:    "   , server_msg)
                    self.debug(200, "Number of Octets:    " , octets)
                    self.debug(200, "Message body:")
                    for line in body:
                        print line
                    #end for
                    return True
                #endif
            finally:
                self.__disconnect__()      
        #endif 
    

    Also here is the POP3 connection, at least how I implemented it…sort of tricky using a string comparison, but it worked for my app:

    def __connect_pop3__(self):
        """\brief Method for connecting to POP3 server                        
           \return True   If connection to POP3 succeeds or if POP3 is already connected
           \return False  If connection to POP3 fails
        """
        #------Check that POP3 is not already connected-----------------------
        if not self.pop3_connected:
            #------Connect POP3-----------------------------------------------
            self.debug(100, 'Connecting POP3 with: ', self.host_name, self.user_name, self.pass_name)
            self.conn_pop3 = POP3(self.host_name)            
            res1 = self.conn_pop3.user(self.user_name)
            string1 = str(res1)      
            self.debug(100, 'User identification result:', string1) 
            res2 = self.conn_pop3.pass_(self.pass_name)        
            string2 = str(res2)                
            self.debug(100, 'Pass identification result:', string2)                        
            #------Check if connection resulted in success--------------------
            #------Server on DavMail returns 'User successfully logged on'----
            if  string2.find('User successfully logged on')<>-1 or string1.find('User successfully logged on')<>-1 :
                self.pop3_connected = True            
                return True
            else:
                return False
            #endif         
        else:       
            self.debug(255, 'POP3 already connected')
            return True
        #endif 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I log into my Launchpad account in a python script? Any sample
Using log4net we would like to log all calls to our ASP.NET MVC controller
I am making a web-based logviewer using extjs. I would like new log-lines to
I would like to monitor a log file that is being written to by
I would like to set the log file name for a log4j and log4net
I would like to remove selected commit log entries from a linear commit tree,
I would like to display details of an xml error log to a user
I would like to create a class that creates and manages log files. I
I am parsing a log and would like an elegant way of calculating the
I am trying to analyse the IIS log and would like to look at

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.