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 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, i found their is a idle method that can notify you with callback when new mail comes, but when i try to use it with imaplib and imaplib2, it doesn't work
@csrgxtu could you please share the details about writing the callback way you tried
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
Hello Budy
I want to check email subject and IF subject is "Database Moved" then script has to send send to Arduino over serial.
How can I do that?
What is correct code?
Can you help me please