-
Notifications
You must be signed in to change notification settings - Fork 0
/
readMail_POP.py
33 lines (30 loc) · 910 Bytes
/
readMail_POP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import poplib
mailServer = 'pop.gmail.com'
emailID = '[email protected]'
emailPass = 'password'
## open connection to mail server (Secured using SSL)
myEmailConnection = poplib.POP3_SSL(mailServer)
## print the response message from server
print(myEmailConnection)
print(myEmailConnection.getwelcome())
## set email address
myEmailConnection.user(emailID)
## set password
myEmailConnection.pass_(emailPass)
## get information about the email address
EmailInformation = myEmailConnection.stat()
print("Number of new emails: %s (%s bytes)" % EmailInformation)
## Reading an email
print("\n\n===\nRead messages\n===\n\n")
## Read all emails
print("*"*10)
print(EmailInformation)
print("*"*10)
numberofmails = EmailInformation[0]
for i in range(numberofmails):
print("-" * 10)
print(i)
print("-" * 10)
for i in range(numberofmails):
for email in myEmailConnection.retr(i + 1)[1]:
print(email)