import serial
import imaplib
from time import sleep
IMAP_SERVER='imap.gmail.com'
IMAP_PORT=993
ser= serial.Serial ('/dev/ttyACM0',9600)
while True:
M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
rc, resp = M.login('user@gmail.com', 'Password')
print rc, resp
M.select()
for msg_num in M.search("INBOX", "UNDELETED")[1][0].split():
msg = M.fetch('1', '(BODY.PEEK[TEXT])')
try:
String = msg[1][0][1][139:148]
except TypeError:
continue
print String
if String == "This is just a test...":
ser.write('0')
sleep(1)
I'm a new beginner in python programming and the above python code is one that I'm using for a program I want to do. When I run this in a terminal I get the response that I have authenticated my account and then it displays the message between characters 139 & 161, which is the following in the example email:
This is just a test...
This is printed out in the terminal. After a few times the program checks my email this error comes out:
Traceback (most recent call last):
File "/home/wilson/Desktop/Best_Gmail_yet _Dont_touch.py", line 11, in <module>
rc, resp = M.login('user@gmail.com', 'password')
File "/usr/lib/python2.6/imaplib.py", line 500, in login
raise self.error(dat[-1])
imaplib.error: [ALERT] Web login required: http://mail.google.com/support /bin/answer.py?answer=78754 (Failure)
Does anyone have any ideas to help out and is there any other way to write to serial, Thanks in advance!