Created
December 14, 2012 02:02
-
-
Save jonathanhculver/4281908 to your computer and use it in GitHub Desktop.
Python script to check gmail for new email every minute and send to Arduino over serial.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imaplib, serial, struct, time | |
class Mail(): | |
def __init__(self): | |
self.user= 'USER' | |
self.password= 'PASS' | |
self.ser = serial.Serial('/dev/tty.usbmodem621', 9600) | |
self.M = imaplib.IMAP4_SSL('imap.gmail.com', '993') | |
self.M.login(self.user, self.password) | |
def checkMail(self): | |
self.M.select() | |
self.unRead = self.M.search(None, 'UnSeen') | |
return len(self.unRead[1][0].split()) | |
def sendData(self): | |
self.numMessages= self.checkMail() | |
#turn the string into packed binary data to send int | |
self.ser.write(struct.pack('B', self.numMessages)) | |
email = Mail() | |
# check for new mail every minute | |
while 1: | |
print 'Sending' | |
email.sendData() | |
time.sleep(60) |
Hi, Could you please help me to write the python code to receive a call when an email received.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@csrgxtu could you please share the details about writing the callback way you tried