Advertisement
xxmbabanexx

GUI Email v1

Jun 13th, 2013
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.81 KB | None
  1. #Email Send v3 Program. It has a basic GUI to send emails.
  2.  
  3. from Tkinter import *
  4. import smtplib
  5. import string
  6. import random
  7.  
  8.  
  9.  
  10. def random_char():
  11.  
  12.     char_select = random.randrange(52)
  13.  
  14.     char_choice = string.ascii_letters[char_select]
  15.  
  16.     return char_choice
  17.  
  18. class Authen(Frame):
  19.     """Holds authentication code and basic GUI stuff"""
  20.     def __init__(self, master):
  21.         """Start Authen GUI"""
  22.         Frame.__init__(self, master)
  23.         self.grid()
  24.         self.Create_Widgets()
  25.  
  26.        
  27.     def Create_Widgets(self):
  28.         """Spawns the widgets"""
  29.         self.Usertext = Label(self, text = "Username: ")
  30.         self.Usertext.grid(row = 0, column = 0)
  31.         self.Username = Entry(self)
  32.         self.Username.grid(row = 0, column = 1)
  33.  
  34.         self.Passtext = Label (self, text = "Password: ")
  35.         self.Passtext.grid(row = 1, column = 0)
  36.         self.Password = Entry (self, show = "*")
  37.         self.Password.grid(row = 1, column = 1)
  38.  
  39.         self.Submit = Button(self, text = "Submit Credits",
  40.                         command = self.authen_credits)
  41.         self.Submit.grid()
  42.        
  43.     def authen_credits(self):
  44.         """Backbone of authen process"""
  45.         Username_mine = self.Username.get()
  46.         Password_mine = self.Password.get()
  47.         server = smtplib.SMTP('smtp.gmail.com:587')
  48.         server.ehlo()
  49.         server.starttls()
  50.         while True:
  51.             try:
  52.                 server.login(Username_mine,Password_mine)
  53.                 #make my screen dimensions work
  54.                 w = 500
  55.                 h = 1000
  56.                 app = Application()
  57.                 app.title("SMTP Mail Client")
  58.                 app.geometry("%dx%d" % (w, h))
  59.                 break
  60.             except smtplib.SMTPAuthenticationError:
  61.                 print "Login Failed"
  62.  
  63.  
  64.  
  65.  
  66.            
  67.        
  68.        
  69.        
  70.  
  71. class Application(Toplevel):
  72.     """Toplevel Frame, holds sendmail stuff"""
  73.     def __init__(self):
  74.         """Start the toplevel Frame"""
  75.         Toplevel.__init__(self)
  76.         self.grid()
  77.         self.entryFun()
  78.         self.mainFun()
  79.        
  80.     def entryFun(self):
  81.         """Holds entry Frame"""
  82.         self.entryFrame = Frame(self)
  83.         self.entryFrame.grid(row = 0, column = 0, sticky = W)
  84.  
  85.         self.To_Lbl = Label(self.entryFrame, text = "TO:  ")
  86.         self.To_Lbl.grid(row = 0, column = 0, sticky = W)
  87.  
  88.         self.To_Entry = Entry(self.entryFrame)
  89.         self.To_Entry.grid(row = 0, column = 1, sticky = W)
  90.  
  91.  
  92.         self.Subject_Lbl = Label(self.entryFrame, text = "Subject:  ")
  93.         self.Subject_Lbl.grid(row = 1, column = 0, sticky = W)
  94.  
  95.         self.Subject_Entry = Entry(self.entryFrame)
  96.         self.Subject_Entry.grid(row = 1, column = 1, sticky = W)
  97.        
  98.     def mainFun(self):
  99.         """Holds body of thing"""
  100.         self.entryFrame = Frame(self)
  101.         self.entryFrame.grid(row = 1, column = 0, sticky = W)
  102.  
  103.        
  104.         self.Body = Text(self.entryFrame, width = 75, height = 50, relief = GROOVE, bd = 5)
  105.         self.Body.grid()
  106.  
  107.         self.send_mail = Button(self, text = "Send Mail",
  108.                                 command = self.send_cmd)
  109.         self.send_mail.grid()
  110.  
  111.     def send_cmd(self):
  112.         Username_mine = passcheck.Create_Widgets.Username.get()
  113.         Password_mine = passcheck.Create_Widgets.Password.get()
  114.         contents = self.Body.get("0.0", END)
  115.         FROM = "Unknown"
  116.         subject = self.Subject_Entry.get()
  117.         recipients = self.To_Entry.get()
  118.         server = smtplib.SMTP('smtp.gmail.com:587')
  119.         server.ehlo()
  120.         server.starttls()
  121.         server.login()
  122.         server.sendmail(FROM, recipients, contents)
  123.  
  124.        
  125.  
  126. root = Tk()
  127. root.title("Login")
  128. root.geometry("500x500")
  129. passcheck = Authen(root)
  130.  
  131. root.mainloop()
Advertisement
RAW Paste Data Copied
Advertisement