Advertisement
Guest User

Untitled

a guest
Aug 1st, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import imaplib, serial, struct, time
  2.  
  3. class Mail():
  4. def __init__(self):
  5. self.user= 'USER'
  6. self.password= 'PASS'
  7. self.ser = serial.Serial('/dev/tty.usbmodem621', 9600)
  8. self.M = imaplib.IMAP4_SSL('imap.gmail.com', '993')
  9. self.M.login(self.user, self.password)
  10.  
  11. def checkMail(self):
  12. self.M.select()
  13. self.unRead = self.M.search(None, 'UnSeen')
  14. return len(self.unRead[1][0].split())
  15.  
  16. def sendData(self):
  17. self.numMessages= self.checkMail()
  18. #turn the string into packed binary data to send int
  19. self.ser.write(struct.pack('B', self.numMessages))
  20.  
  21. email = Mail()
  22.  
  23. # check for new mail every minute
  24. while 1:
  25. print 'Sending'
  26. email.sendData()
  27. time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement