def save(self, event): account_name = self.account_name.get() sender_name = self.sender_name.get() smtp_server = self.smtp_server.get() smtp_port = self.smtp_port.get() smtp_username = self.smtp_username.get() smtp_password = self.smtp_password.get() imap_server = self.imap_server.get() imap_port = self.imap_port.get() imap_username = self.imap_username.get() imap_password = self.imap_password.get() db = SqliteDBC("emaildb.db") if len(db.table("accounts").select().eq({"account_name":account_name}).fetch()) > 0: tkMessageBox.showwarning("Invalid Account Name", "This account name has been registered already!") else: db.table("accounts").insert({"account_name":account_name, "sender_name":sender_name, "smtp_username":smtp_username, "smtp_server":smtp_server, "smtp_port":smtp_port, "smtp_password":smtp_password, "imap_username":imap_username, "imap_server":imap_server, "imap_port":imap_port, "imap_password":imap_password})
def set_db(self): db = SqliteDBC("emaildb.db") db.execute_sql("""CREATE TABLE IF NOT EXISTS accounts ( account_name text PRIMARY KEY, sender_name text, smtp_username text NOT NULL, smtp_password text NOT NULL, smtp_server text NOT NULL, smtp_port text NOT NULL, imap_username text NOT NULL, imap_password text NOT NULL, imap_server text NOT NULL, imap_port text NOT NULL)""")
def send_mail(self, event): selected_account = self.selected_account.get() mail_to = self.mail_to.get() mail_subject = self.mail_subject.get() mail_content = self.mail_content.get("1.0", END) account_name = selected_account[selected_account.find("|")+1:].strip() db = SqliteDBC("emaildb.db") account = db.table("accounts").select(["sender_name", "smtp_server", "smtp_port", "smtp_username", "smtp_password"]).eq({"account_name":account_name}).limit(1).fetch() if len(account) > 0: try: message = """From: {}<{}>\nTo: {}\nSubject: {}\n\n{} """ .format(account[0], account[3], mail_to, mail_subject, mail_content) server = smtplib.SMTP_SSL( "{}:{}".format(account[1], account[2]) ) server.ehlo() server.login( account[3], account[4] ) server.sendmail( account[3], mail_to, message) server.close() print 'successfully sent the mail' except Exception as e: print e print "failed to send mail"
def get_accounts(self): db = SqliteDBC("emaildb.db") self.mail_accounts = db.table("accounts").select(["sender_name", "smtp_username", "account_name"]).fetch() print self.mail_accounts return self.mail_accounts