-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgmail_imap.py
42 lines (29 loc) · 1.1 KB
/
gmail_imap.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
import imaplib
import gmail_mailboxes, gmail_messages, gmail_message
class gmail_imap:
def __init__ (self, username, password):
self.imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
self.username = username
self.password = password
self.loggedIn = False
self.mailboxes = gmail_mailboxes.gmail_mailboxes(self)
self.messages = gmail_messages.gmail_messages(self)
def login (self):
self.imap_server.login(self.username,self.password)
self.loggedIn = True
def logout (self):
self.imap_server.close()
self.imap_server.logout()
self.loggedIn = False
if __name__ == '__main__':
import getpass
gmail = gmail_imap(getpass.getuser(),getpass.getpass())
gmail.mailboxes.load()
print gmail.mailboxes
gmail.messages.process("INBOX")
print gmail.messages
for msg in gmail.messages[0:2]:
message = gmail.messages.getMessage(msg.uid)
print message
print message.Body
gmail.logout()