
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
POP3 protocol client in Python
The poolib module from Python's standard library defines POP3 and POP3_SSL classes. POP3 class encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. POP3_SSL classsupports POP3 servers that use SSL as an underlying protocol layer.
POP3 protocolis obsolescent as its implementation quality of POP3 servers is quite poor. If your mailserver supports IMAP, it is recommended to use the imaplib.IMAP4 class.
Both classes have following methods defined −
getwelcome()
Returns the greeting string sent by the POP3 server.
user(username)
Send user command, response should indicate that a password is required.
pass_(password)
Send password.
Stat()
Get mailbox status. The result contains 2 integers: (message count, mailbox size).
list()
Request message list, result is in the form (response, ['mesg_num octets', ...], octets).
retr()
Retrieve message of specified index, and set its seen flag.
Dele()
Flag message number which for deletion.
Top()
Retrieves the message header plus number of lines of the message after the header of message
quit(): Signoff
commit changes, unlock mailbox, drop connection.
Example
Following code retrieves all unread messages from gmail’s POP server.
import poplib box = poplib.POP3_SSL('pop.googlemail.com', '995') box.user("YourGmailUserName") box.pass_('YourPassword') N = len(box.list()[1]) for i in range(N): for msg in box.retr(i+1)[1]: print (msg) box.quit()
Before running above script ensure that your gmail account is configure to allow less secure apps.
- Related Articles
- FTP protocol client in Python
- SMTP protocol client in Python (smtplib)
- Post Office Protocol, Version 3 (POP3)
- Differences between POP3 and IMAP
- Difference between SMTP and POP3
- XMLRPC server and client modules in Python
- Differentiate between IMAP and POP3 in Computer Network.
- Protocol and Protocol Hierarchies
- Python program to find the IP Address of the client
- Client-Server Programming in Android
- Bundle Protocol
- CAN Protocol
- Client Server Computing
- MySQL Client Programs
- MySQL Client Options
