daily pastebin goal
3%
SHARE
TWEET

ehlo.py - mini interface para envio de e-mails

a guest Oct 22nd, 2017 193 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. #coding: utf-8
  3. """
  4.    Ehlo World - Mini interface para envio de e-mails feita em python e tkinter
  5. """
  6.  
  7. import email
  8. import smtplib
  9. import mimetypes
  10. from Tkinter import *
  11. from ScrolledText import *
  12. import email.mime.application
  13. import Tkinter, tkFileDialog, tkFont, tkMessageBox
  14.  
  15. files = list()
  16. wordlist = str()
  17.  
  18. def set_flood():
  19.     if flood_chk.get() == 1:
  20.         num_flood.delete(0, END)
  21.         num_flood.config(state=NORMAL)      
  22.     else:
  23.         num_flood.delete(0, END)
  24.         num_flood.config(state=DISABLED)
  25.  
  26. def add_file():
  27.     file = tkFileDialog.askopenfile(parent=opcoes, mode="rb", title="Escolher Arquivo")
  28.     if file != None:
  29.         files.append(file.name)
  30.         file_msg.config(text="Arquivos adicionado: "+str(len(files)), width=370, fg="green", font=("Helvetica", 10), justify=CENTER )
  31.         file_msg.grid(row=5, sticky=W, columnspan=2)
  32.         file.close()
  33.     else:
  34.         pass
  35.  
  36. def add_list():
  37.     if list_chk.get() == 0:
  38.         to_entry.config(state=NORMAL)
  39.         list_text.delete(1.0, END)
  40.         list_chk.set(0)
  41.     else:
  42.         lista = tkFileDialog.askopenfile(parent=opcoes, mode="rb", title="Escolher Lista")
  43.         if lista != None:
  44.             data = lista.read()
  45.             list_text.insert(END, data)
  46.             to_entry.delete(0, END)
  47.             to_entry.config(state=DISABLED)
  48.             wordlist = lista.name
  49.             lista.close()
  50.         else:
  51.             to_entry.config(state=NORMAL)
  52.             list_chk.set(0)
  53.    
  54. def send_email():
  55.     if list_chk.get() == 0:
  56.         body = email.mime.Multipart.MIMEMultipart()
  57.         body["From"] = from_entry.get()
  58.         fromaddr = from_entry.get()
  59.         body["To"] = to_entry.get()
  60.         to = str(to_entry.get())
  61.         body["Subject"] = subject_entry.get()
  62.         data = email.mime.Text.MIMEText(msg_text.get(1.0, END))
  63.         body.attach(data)
  64.  
  65.         for file in files:
  66.             fp = open(file, "rb")
  67.             if fp != None:
  68.                 slash = fp.name.split("/")
  69.                 name = slash[-1].lower()
  70.                 dot = name.split(".")
  71.                 ext = dot[-1].lower()
  72.                 att = email.mime.application.MIMEApplication(fp.read(),_subtype=ext)
  73.                 att.add_header("Content-Disposition","attachment",filename=name)
  74.                 body.attach(att)
  75.                 fp.close()
  76.             else:
  77.                 pass
  78.        
  79.         if ssl_chk.get() == 1:
  80.             s = smtplib.SMTP_SSL(server_entry.get(), int(port_entry.get()))
  81.         else:
  82.             s = smtplib.SMTP(server_entry.get(), int(port_entry.get()))
  83.  
  84.         username = login_entry.get()
  85.         password = password_entry.get()
  86.         s.login(username, password)
  87.                
  88.         if flood_chk.get() == 1:
  89.             for num in range(0, int(num_flood.get())):
  90.                 s.sendmail(fromaddr, to, body.as_string())
  91.                 print "[ {} ] e-mail enviado para [ {} ]".format(num, to)
  92.         else:
  93.             print
  94.             print "[ {} ] e-mail enviado para [ {} ]".format(num, to)
  95.             s.quit()
  96.         del(body)
  97.     else:
  98.         fp = open(wordlist, "r")
  99.         if fp != None:
  100.             for mail in fp.readlines():
  101.                 body = email.mime.Multipart.MIMEMultipart()
  102.                 body["From"] = from_entry.get()
  103.                 fromaddr = from_entry.get()
  104.                 body["To"] = mail
  105.                 to = str(mail)
  106.                 body["Subject"] = subject_entry.get()
  107.                 data = email.mime.Text.MIMEText(msg_text.get(1.0, END))
  108.                 body.attach(data)
  109.                 for file in files:
  110.                     fp = open(file, "rb")
  111.                     if fp != None:
  112.                         slash = fp.name.split("/")
  113.                         name = str(slash[-1])
  114.                         dot = name.split(".")
  115.                         ext = str(dot[-1])
  116.                         att = email.mime.application.MIMEApplication(fp.read(),_subtype=ext.lower())
  117.                         att.add_header("Content-Disposition","attachment",filename=name)
  118.                         body.attach(att)
  119.                         fp.close()
  120.                     else:
  121.                         pass
  122.                    
  123.                 if ssl_chk.get() == 1:
  124.                     s = smtplib.SMTP_SSL(server_entry.get(), int(port_entry.get()))
  125.                 else:
  126.                     s = smtplib.SMTP(server_entry.get(), int(port_entry.get()))
  127.                
  128.                 username = login_entry.get()
  129.                 password = password_entry.get()
  130.                 s.login(username, password)
  131.                
  132.                 if flood_chk.get() == 1:
  133.                     for num in range(0, int(num_flood.get())):
  134.                         s.sendmail(fromaddr, to, body.as_string())
  135.                         print "[ {} ] e-mail enviado para [ {} ]".format(num, to)
  136.                 else:
  137.                     print
  138.                     print "[ {} ] e-mail enviado para [ {} ]".format(num, to)
  139.                     s.quit()
  140.                 del(body)
  141.         else:
  142.             pass        
  143.  
  144. root = Tkinter.Tk()
  145. root.config(width=800, height=600, bg="gray")
  146. #root.iconbitmap("ehlo.ico")
  147. root.title(" EHLO WORLD")
  148.  
  149. login = Tkinter.Frame(root, bd=1, bg="gray")
  150. login.config(width=400, height=600, padx=5)
  151. login.pack(fill=BOTH, side=LEFT,  padx=5, pady=5)
  152.  
  153. login_label = Label(login, text="Email:", font=("Helvetica"), bg="gray")
  154. login_label.grid(row=0, sticky=W)
  155. login_entry = Entry(login)
  156. login_entry.delete(0, END)
  157. login_entry.insert(END, "")
  158. login_entry.grid(row=0, column=1, sticky=W)
  159.  
  160. password_label = Label(login, text="Senha:", font=("Helvetica"), bg="gray")
  161. password_label.grid(row=1, sticky=W)
  162. password_entry = Entry(login)
  163. password_entry.delete(0, END)
  164. password_entry.insert(END, "")
  165. password_entry.grid(row=1, column=1, sticky=W)
  166.  
  167. server_label = Label(login, text="Servidor:", font=("Helvetica"), bg="gray")
  168. server_label.grid(row=2, sticky=W)
  169. server_entry = Entry(login)
  170. server_entry.delete(0, END)
  171. server_entry.insert(END, "")
  172. server_entry.grid(row=2, column=1, sticky=W)
  173.  
  174. port_label = Label(login, text="Porta:", font=("Helvetica"), bg="gray")
  175. port_label.grid(row=3, sticky=W)
  176. port_entry = Entry(login)
  177. port_entry.delete(0, END)
  178. port_entry.insert(END, "")
  179. port_entry.grid(row=3, column=1, sticky=W)
  180.  
  181. ssl_chk = IntVar()
  182. ssl_box = Checkbutton(login, text="Habilitar SSL", font=("Helvetica"), bg="gray", onvalue=1, offvalue=0, variable=ssl_chk)
  183. ssl_box.grid(row=4, sticky=W)
  184.  
  185. write_msg = Label(login, text="Escrever mensagem:", font=("Helvetica"), bg="gray")
  186. write_msg.grid(sticky=W)
  187. msg_text = ScrolledText(login, width=50, height=22)
  188. msg_text.grid(pady=5, columnspan=3,  sticky=W)
  189.  
  190. opcoes = Tkinter.Frame(root, bd=1, bg="gray")
  191. opcoes.config(width=400, height=600, padx=5, pady=5)
  192. opcoes.pack(fill=BOTH, side=LEFT, padx=5)
  193. from_label = Label(opcoes, text="De: ", font=("Helvetica"), bg="gray" )
  194. from_label.grid(row=0, sticky=W)
  195. from_entry = Entry(opcoes)
  196. from_entry.delete(0, END)
  197. from_entry.insert(END, "")
  198. from_entry.grid(row=0, column=1, sticky=W)
  199.  
  200. to_label = Label(opcoes, text="Para: ", font=("Helvetica"),  bg="gray")
  201. to_label.grid(row=1, sticky=W)
  202. to_entry = Entry(opcoes)
  203. to_entry.delete(0, END)
  204. to_entry.insert(END, "")
  205. to_entry.grid(row=1, column=1, sticky=W)
  206.  
  207. subject_label = Label(opcoes, text="Assunto: ", font=("Helvetica"),  bg="gray")
  208. subject_label.grid(row=2, sticky=W)
  209. subject_entry = Entry(opcoes)
  210. subject_entry.delete(0, END)
  211. subject_entry.insert(END, "")
  212. subject_entry.grid(row=2, column=1, sticky=W)
  213.  
  214. flood_chk = IntVar()
  215. flood_box = Checkbutton(opcoes, text="Flood", font=("Helvetica"), bg="gray", onvalue=1, offvalue=0, variable=flood_chk, command=set_flood)
  216. flood_box.grid(row=3, sticky=W)
  217.  
  218. num_flood = Entry(opcoes, width=2, state=DISABLED)
  219. num_flood.grid(row=3, column=1, sticky=W)
  220.  
  221. add_file_label = Label(opcoes, text="Adicionar arquivos: ", font=("Helvetica"),  bg="gray")
  222. add_file_label.grid(row=4, sticky=W)
  223. file_btn = Button(opcoes, text="Pesquisar", font=("Helvetica"), width=12, height=1, command=add_file)
  224. file_btn.grid(row=4, column=1, padx=5, sticky=W)
  225.  
  226. file_msg = Message(opcoes)
  227.  
  228. list_chk = IntVar()
  229. list_box = Checkbutton(opcoes, text="Adicionar lista", font=("Helvetica"), bg="gray", onvalue=1, offvalue=0, variable=list_chk, command=add_list)
  230. list_box.grid(row=6,  sticky=W)
  231. list_text = ScrolledText(opcoes, width=50, height=20)
  232. list_text.grid(row=7, columnspan=3, sticky=W)
  233.  
  234. file_btn = Button(opcoes, text="Enviar", font=("Helvetica"), width=6, height=1, command=send_email)
  235. file_btn.grid(row=8, padx=5)
  236.  
  237. file_btn = Button(opcoes, text="Sair", font=("Helvetica"), width=6, height=1, command=root.quit)
  238. file_btn.grid(row=8, column=1, padx=5)
  239.  
  240. root.resizable(width=False, height=False)
  241. root.mainloop()
  242. root.destroy()
  243.  
  244. # code by cm9vdA
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top