1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
| #! python
# -*- coding: cp1252 -*-
from Tkinter import *
import Tkinter as Tk
import tkMessageBox
import tkFileDialog
import webbrowser
import os
import smtplib
import tkMessageBox as Msg
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.Utils import formatdate
############################################################################################################################
############################################################################################################################
## Fenêtre principale
root = Tk.Tk()
root.geometry("270x650")
root.title("Envoie de mail")
root.iconbitmap("xp.ico")
root.config (bg="#999")
root.resizable(width=False, height=False)
root.option_add('*font', ('verdana', 8, 'normal'))
############################################################################################################################
############################################################################################################################
##Fenetres du menu
#################################################
#################################################
def About(): Msg.showinfo("A propos", "Version 1.0 \n Développer par Frelon")
#################################################
#################################################
def Ouvrir(event):tkFileDialog.askopenfilename(parent=root,
initialdir="/",
initialfile="",
filetypes = [("All", "*"),
("Fichiers Images","*.jpg;*.bmp;*.gif"),
("Fichiers Texte","*.txt;*.doc;*.rtf"),
("Fichiers Exel","*.xls")],
title='Choisissez un repertoire')
#################################################
#################################################
def Enregistrer():
f = open("mail.txt", "w")
f.write(str(formatdate()))
f.write("\n------------------------------------------ \n")
f.write("Serveur SMTP : ")
f.write(lab['text'])
f.write("\n")
f.write("Expéditeur : ")
f.write(str(ex.get()))
f.write("\n")
f.write("Destinataire : ")
f.write(str(des.get()))
f.write("\n")
f.write("Titre : ")
f.write(str(ti.get()))
f.write("\n")
f.write("Piéces Jointes : ")
f.write(str(piece_jointe.get()))
f.write("\n")
f.write("Message : ")
f.write(str(msg.get("0.0",END)))
f.write("\n")
f.close()
#################################################
#################################################
def EnregistrerSous():enregistrer_sous=tkFileDialog.asksaveasfilename(parent=root,
initialdir="/",
title="Enregistrer sous ...",
filetypes = [("All", "*"),
("Fichiers Python","*.py;*.pyw")])
#################################################
#################################################
def Nouveau():nouveau=tkFileDialog.asksaveasfilename(parent=root,
initialdir="/",
title="Nouveau",
filetypes = [("All", "*"),
("Fichiers Python","*.py;*.pyw")])
def Apropos():
root2 = Tk.Tk()
root2.geometry("400x250")
root2.title("A Propos")
root2.iconbitmap("xp.ico")
root2.config (bg="#999")
root2.resizable(width=False, height=False)
#################################################
Label(root2, text='Envoie de mail: Informations - Version', font= 'arial 16', bg ='#999',fg='#fff').grid(column=0, row=0, columnspan = 2, pady = 5, padx=10)
Label(root2, text='\n - Codeur: Frelon', bg ='#999',fg='#fff').grid(column=1, row=1, sticky = W)
Label(root2, text=' - Version: 1.0 (--/--/07)', bg ='#999',fg='#fff').grid(column=1, row=2, sticky = W)
Label(root2, text=' - Release: --/--/07\n\n', bg ='#999',fg='#fff').grid(column=1, row=3, sticky = W)
Label(root2, text=' - Pour tout contact, bug ou suggestion: rom911@hotmail.com', bg ='#999',fg='#fff',relief=GROOVE).grid(column=1, row=4, sticky = W)
Label(root2, text='', font='arial 11', bg ='#999',fg='#fff').grid(column=1, row=5, columnspan = 2)
#################################################
#################################################
def Option():
root3 = Tk.Tk()
root3.geometry("400x250")
root3.title("A Propos")
root3.iconbitmap("xp.ico")
root3.config (bg="#999")
root3.resizable(width=False, height=False)
#################################################
#################################################
def Aide(): webbrowser.open('http://www.google.fr')
#################################################
#################################################
def Quitter(): root.destroy()
#################################################
#################################################
#Formule pour la liste
def onSelect(e):
select=listb.get(listb.curselection())
lab.configure(text=select, fg="#ff0")
listb.configure()
return select
listb=Listbox(root, bg ='#999',fg='#fff',relief = GROOVE, bd = 0, width = 20, height = 15)
lab=Label(root,text="Choissisez un Server SMTP*", bg ='#999',fg='#ff0')
listb.pack(pady =10)
lab.pack()
i=0
# Insertion des server smtp
for smtp in ["smtp.wanadoo.fr",
"smtp.9online.fr",
"smtp.fr.aol.com",
"smtp.lycos.co.uk",
"smtp.cegetel.net",
"smtp.free.fr",
"smtp.freesurf.fr",
"smtp.gmail.com",
"smtp.laposte.net",
"mail.noos.fr",
"smtp.orange.fr",
"smtp.tele2.fr",
"smtp.tiscali.fr",
"smtp.mail.yahoo.fr"]:
listb.insert(i,smtp)
i+=1
# Un double click dans la liste appellera la fonction onSelect:
listb.bind('<Double-1>',onSelect)
#################################################
#################################################
#Bouton + formule
def envoie(*args):
msge=MIMEMultipart()
msge['subject']=ti.get()
msge['from']=ex.get()
msge['to']=des.get()
msge['Date'] = formatdate(localtime=True)
message=MIMEBase('text','html')
message.set_payload(msg.get('0.0',END))
msge.attach(message)
fp=open('mail.txt','rb')
img=MIMEBase('text','plain')
img.set_payload(fp.read())
fp.close()
msge.attach(img)
smtp1.connect(lab['text'],25)
#smtp1.login(user.get(),login.get())
smtp1.sendmail(ex.get(),des.get(),msge.as_string())
smtp1.quit()
#################################################
#################################################
def joindre():
piece_jointe.delete(0, END)
nom_fichiers = tkFileDialog.askopenfilename(parent=root,
initialdir="/",
initialfile="",
filetypes = [("All", "*"),
("Fichiers Images","*.jpg;*.bmp;*.gif"),
("Fichiers Texte","*.txt;*.doc;*.rtf"),
("Fichiers Exel","*.xls")],
title='Choisissez un repertoire')
Adresse_fichier=nom_fichiers.split("/")
print "Adresse du fichier :",nom_fichiers
nom_fichiers=Adresse_fichier[-1]
print "Nom du fichier : ",nom_fichiers
piece_jointe.insert(0,nom_fichiers,)
#################################################
#################################################
def temps():
locale.setlocale(locale.LC_ALL,'') # Permet de savoir en quelle langue est votre PC
temp=time.strftime('Nous somme le %A %d %B %Y et il est %H h %M min et %S s')
print temps
## Barre de menu
mainmenu = Tk.Menu(root)
## Fichier
menuFichier = Tk.Menu(mainmenu, tearoff = 0)
## Ajout d'une option au menu Fichier
menuFichier.add_command(label = "Ouvrir Ctrl + O", command = Ouvrir)
root.bind_all("<Control-o>", Ouvrir)
menuFichier.add_command(label = "Nouveau Ctrl + O", command = Nouveau)
menuFichier.add_separator()
menuFichier.add_command(label = "Enregistrer Ctrl +S ", command = Enregistrer, underline=6)
root.bind_all("<Control-s>", Enregistrer)
menuFichier.add_command(label = "Enregistrer sous ... Ctrl + N", command = EnregistrerSous, underline=1)
root.bind_all("<Control-n>", EnregistrerSous)
menuFichier.add_separator()
menuFichier.add_command(label = "Quitter", underline=0, background='white', activebackground='#fff', command = Quitter)
##Edition
menuEdition = Tk.Menu(mainmenu, tearoff = 0)
## Ajout d'une option au menu Help
menuEdition.add_command(label = "Option", command = Option)
## Aide
menuAide = Tk.Menu(mainmenu, tearoff = 0)
## Ajout d'une option au menu Help
menuAide.add_command(label="A propos", command=Apropos)
menuAide.add_command(label="Aide", command=Aide)
##Option Menu Principale
mainmenu.add_cascade(label = "Fichier", menu = menuFichier)
mainmenu.add_cascade(label = "Edition", menu = menuEdition)
mainmenu.add_cascade(label = "Aide", menu = menuAide)
##Fin du Menu
root.config(menu = mainmenu)
############################################################################################################################
############################################################################################################################
#Formulaire envoie mail
Label(root, text ="Expéditeur : ", bg ='#999',fg='#fff').pack(side =TOP, anchor =W, pady =0)
ex = Entry(root, width =20)
ex.insert(0,"@free.fr")
ex.pack(side =TOP, anchor =W, pady =0)
#userlabel=Label(root,text="user :", bg ='#999',fg='#fff')
#userlabel.pack()
#user=Entry(root,width=30)
#user.pack()
#loginlabel=Label(text="login :", bg ='#999',fg='#fff')
#loginlabel.pack()
#login=Entry(root,width=30)
#login.pack()
Label(root, text ="Destinataire : ", bg ='#999',fg='#fff').pack(side =TOP, anchor =W, pady =0)
des = Entry(root, width=20, background="white")
des.insert(0,"@hotmail.com")
des.pack(side =TOP, anchor =W, pady =0)
Label(root, text ="Titre : ", bg ='#999',fg='#fff').pack(side =TOP, anchor =W, pady =0)
ti = Entry(root, width=30, background="white")
ti.insert(0,"teste titre")
ti.pack(side =TOP, anchor =W, pady =0)
Label(root, text ="Pieces Jointe : ", bg ='#999',fg='#fff').pack(side =TOP, anchor =W, pady =0)
piece_jointe = Entry(root, width=30, background="white")
piece_jointe.pack(side =TOP, anchor =W, pady =0)
piece_jointe.focus()
bouton=Button(root, command=joindre, text="Joindre...").pack(side =TOP, anchor =E, pady =4)
Label(root, text ="Message :", bg ='#999',fg='#fff').pack(side =TOP, anchor =W, pady =0)
msg = Text(root, width=40, height=10, background="#EEE")
msg.pack(side =TOP, anchor =W, pady =0)
smtp1=smtplib.SMTP()
bouton=Button(root, command=envoie, text="Envoyer").pack(side =TOP, anchor =E, pady =4)
##Insere le texte dans la fenetre
root.mainloop()
root2.mainloop() |
Partager