def main(): # register your callback register(MyCallback) imap_server = 'imap.gmail.com' imap_user = '******' imap_password = getpass.getpass() mailbot = MailBot(imap_server, imap_user, imap_password, port=993, ssl=True) #conn = imaplib.IMAP4_SSL(imap_server) # (retcode, capabilities) = conn.login(imap_user, imap_password) # check the unprocessed messages and trigger the callback mailbot.process_messages()
e['Body'] = self.get_email_body() f = features_for_email(e) est = lr.predict(f)[0] est = int(math.ceil(est)) if "<*****@*****.**>" in e['To'] or "*****@*****.**" in e['To']: if est > 2 and est < 168: print "Sending email for " + str(est) + " hour estimate to " + e['From'] send_email(e['From'], est, reply=self.message['Message-ID']) else: print "Did not send email for " + str(est) + " hour estimate to " + e['From'] else: print "Did not respond to " + e['From'] + " because the message was not directed to me" except: print "Error occurred - aborting..." mailbot = MailBot('imap.gmail.com', os.environ['GMAIL_USER'], os.environ['GMAIL_PASS'], port=993, ssl=True) lr = joblib.load('lr.pkl') # register your callback register(Autoresponder) print "Processing new messages..." # check the unprocessed messages and trigger the callback mailbot.process_messages()
from mailbot import MailBot, register, Callback from pprint import pprint import getpass class MyCallback(Callback): #rules = {'subject': ['lol'], 'from': [r'@brown.edu']} def trigger(self): print(self.message.keys()) print(self.message.values()) #print("Mail received for {0}".format(self.matches['from'][0])) mailbot = MailBot('imap.gmail.com', '*****@*****.**', getpass.getpass(), port=993, ssl=True) register(MyCallback) mailbot.process_messages()
if est > 2 and est < 168: print "Sending email for " + str( est) + " hour estimate to " + e['From'] send_email(e['From'], est, reply=self.message['Message-ID']) else: print "Did not send email for " + str( est) + " hour estimate to " + e['From'] else: print "Did not respond to " + e[ 'From'] + " because the message was not directed to me" except: print "Error occurred - aborting..." mailbot = MailBot('imap.gmail.com', os.environ['GMAIL_USER'], os.environ['GMAIL_PASS'], port=993, ssl=True) lr = joblib.load('lr.pkl') # register your callback register(Autoresponder) print "Processing new messages..." # check the unprocessed messages and trigger the callback mailbot.process_messages()