-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmail information.py
55 lines (47 loc) · 1.92 KB
/
Email information.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import imaplib
def connectServer():
email = input("## Please enter your Email: ")
password = input("### Please enter your Password: ")
imapServer = imaplib.IMAP4_SSL('imap.gmail.com') # Connection to the server
try:
imapServer.login(email, password) # Log in to your Email account
except imaplib.IMAP4.error:
print("Invalid Email or Password!. Program terminated.\n")
return None
return imapServer
def read_readEmails(imapServer):
imapServer.select('INBOX') # Choosing an Email box
result, data = imapServer.search(None, 'SEEN') # Search in read Emails
readEmails = data[0].split()
print("Your read Emails:\n")
for num in readEmails:
result, data = imapServer.fetch(num, '(RFC822)')
print(data[0][1])
def read_unreadEmails(imapServer):
imapServer.select('INBOX')
result, data = imapServer.search(None, 'UNSEEN')
unread_emails = data[0].split()
print("Your unread Emails:\n")
for num in unread_emails:
result, data = imapServer.fetch(num, '(RFC822)')
print(data[0][1])
def main():
print("\n-------------------------------------------------")
imapServer = connectServer()
if not imapServer:
return
print("\n-----------------------------------------")
print("| Please select the desired option: |")
print("| 1. View read Emails |")
print("| 2. View unread Emails |")
print("-----------------------------------------")
userChoice = input("Your Choice: ")
if userChoice == "1":
read_readEmails(imapServer)
elif userChoice == "2":
read_unreadEmails(imapServer)
else:
print("Invalid Selection!")
imapServer.logout() # disconnection
if __name__ == "__main__":
main()