Basically I am just trying to figure out a way to run certain processes while I am out of the office. I want to just set up a quick template code by performing a fairly simple process (like restarting my printer). The issue that I am having at the moment is that when I run this code I can't figure out a good way to kill the code entirely after the process has executed.
The code that I am using:
import imaplib
import time
import sys
user = '#my email'
password = '#my password'
server = 'imap.gmail.com'
mailbox = 'Inbox'
while True:
try:
imap = imaplib.IMAP4_SSL(server)
imap.login(user, password)
email_count = imap.select(mailbox, True)
results, data = imap.search(None, '(FROM "#my email" SUBJECT "Test")')
ids = data[0]
id_list = ids.split()
latest_email_id = id_list[-1]
result, data = imap.fetch(latest_email_id, "(RFC822)")
raw_email = data[0][1]
print(raw_email)
imap.logout
except:
print("no email found")
time.sleep(60)