IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

Logiciel envoie mail (probleme)


Sujet :

Tkinter Python

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 16
    Points : 8
    Points
    8
    Par défaut Logiciel envoie mail (probleme)
    slt a tous,
    sa fait quelle que jour que je touche a python et j'aimerai savoir si vous pouvier m'aider. voila mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    #! python
    # -*- coding: cp1252 -*-
    from Tkinter import *
    import Tkinter as Tk
    import tkMessageBox as Msg
     
     
    ## Fenêtre principale
    root = Tk.Tk()   
    root.geometry("500x600")
    root.title("Envoie de mail")
    root.iconbitmap("xp.ico")
     
    ##Fenetres du menu
    def About(): Msg.showinfo("A propos", "Version 1.0 \n Développer par Frelon")
     
     
    ## Barre de menu
    mainmenu = Tk.Menu(root)  
     
    ## Menu fils menuFichier
    menuFichier = Tk.Menu(mainmenu)
    ## Ajout d'une option au menu Fichier
    menuFichier.add_command(label="Quitter", command=root.destroy)
     
    ## Menu fils menuFichier
    menuHelp = Tk.Menu(mainmenu)
    ## Ajout d'une option au menu Help
    menuHelp.add_command(label="A propos", command=About)
     
    ##Option Menu Principale
    mainmenu.add_cascade(label = "Fichier", menu=menuFichier)
    mainmenu.add_cascade(label = "?", menu=menuHelp)
     
    ##Fin du Menu
    root.config(menu = mainmenu)
     
    ##Texte
    Label(root, text ="Envoyer des mails").pack()
     
     
     
    #Formule pour la liste
    def onSelect(e):
        select=listb.get(listb.curselection())
        lab.configure(text=select, fg="black")
        listb.configure()
     
     
     
    listb=Listbox(root)
    lab=Label(root,text="", fg="red")
    listb.pack()
    lab.pack()
     
    # Insertion des server smtp
    for  smtp  in  ["smtp.neuf.fr","smtp.9online.fr","smtp.fr.aol.com","smtp.lycos.co.uk","smtp.cegetel.net","smtp.free.fr",
                       "smtp.freesurf.fr","smtp.gawab.com","smtp.gmail.com","smtp.ifrance.com","smtp.laposte.net",
                       "mail.noos.fr","smtp.orange.fr","smtp.tele2.fr","smtp.tiscali.fr","smtp.wanadoo.fr",
                       "smtp.mail.yahoo.fr"]:
            listb.insert(END,smtp)
     
    # Un double click dans la liste appellera la fonction onSelect:		
    listb.bind('<Double-1>',onSelect)
     
     
     
     
    #Formulaire envoie mail
    Label(root, text ="Expéditeur : ").pack()
    ex = Entry(root, width =30)
    ex.pack()
     
    Label(root, text ="Destinataire : ").pack()
    des = Entry(root, width=30, background="white")
    des.pack()
     
    Label(root, text ="Titre : ").pack()
    ti = Entry(root, width=30, background="white")
    ti.pack()
     
     
    Label(root, text ="Message : ").pack()
    msg = Text(root, width=30, height=10, background="#EEE")
    msg.pack()
     
    #Bouton + formule
    def envoie():
        print valeur.get()
     
    bouton=Button(root, command=envoie, text="Envoyer")
    bouton.pack()
     
    ##Insere le texte dans la fenetre
    root.mainloop()
    je voudrai que kan apres avoir choisie le server smtp, puis remplie le formulaire
    je click sur le bouton et il envoie le message. jai trouver sur internet
    un bout de code pour envoyer des mail depuis la console mais je ne sais pas comment transformer pour le mettre dans mon application. voici le code pour envoyer les mail depuis la console:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    import smtplib
     
    def prompt(prompt):
        return raw_input(prompt).strip()
     
    de = prompt("De: ")
    a  = prompt("à: ").split()
    print "Entrer le message et finir par Ctrl+D :"
     
    # Add the From: and To: headers at the start!
    msg = ("De: %s\r\n a: %s\r\n\r\n"
           % (de, ", ".join(a)))
    while 1:
        try:
            line = raw_input()
        except EOFError:
            break
        if not line:
            break
        msg = msg + line
     
    print "Nombre de caractere" + repr(len(msg))
     
    server = smtplib.SMTP('smtp.free.fr')
    server.set_debuglevel(1)
    server.sendmail(de, a, msg)
    server.quit()
    merci pour votre aide

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut voili voilou voila
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    import smtplib
     
    # -*- coding: cp1252 -*-
    from Tkinter import *
    import Tkinter as Tk
    import tkMessageBox as Msg
     
     
    ## Fenêtre principale
    root = Tk.Tk()   
    root.geometry("500x600")
    root.title("Envoie de mail")
    #root.iconbitmap("xp.ico")
     
    ##Fenetres du menu
    def About(): Msg.showinfo("A propos", "Version 1.0 \n Développer par Frelon")
     
     
    ## Barre de menu
    mainmenu = Tk.Menu(root)  
     
    ## Menu fils menuFichier
    menuFichier = Tk.Menu(mainmenu)
    ## Ajout d'une option au menu Fichier
    menuFichier.add_command(label="Quitter", command=root.destroy)
     
    ## Menu fils menuFichier
    menuHelp = Tk.Menu(mainmenu)
    ## Ajout d'une option au menu Help
    menuHelp.add_command(label="A propos", command=About)
     
    ##Option Menu Principale
    mainmenu.add_cascade(label = "Fichier", menu=menuFichier)
    mainmenu.add_cascade(label = "?", menu=menuHelp)
     
    ##Fin du Menu
    root.config(menu = mainmenu)
     
    ##Texte
    Label(root, text ="Envoyer des mails").pack()
     
     
     
    #Formule pour la liste
    def onSelect(e):
        select=listb.get(listb.curselection())
        lab.configure(text=select, fg="black")
        listb.configure()
        return select
     
     
    listb=Listbox(root)
    lab=Label(root,text="", fg="red")
    listb.pack()
    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.gawab.com","smtp.gmail.com","smtp.ifrance.com","smtp.laposte.net",
                       "mail.noos.fr","smtp.orange.fr","smtp.tele2.fr","smtp.tiscali.fr","smtp.wanadoo.fr",
                       "smtp.mail.yahoo.fr","smtp.wanadoo.fr"]:
            listb.insert(i,smtp)
            i+=1		
    # Un double click dans la liste appellera la fonction onSelect:		
    listb.bind('<Double-1>',onSelect)
     
     
     
     
    #Formulaire envoie mail
    Label(root, text ="Expéditeur : ").pack()
    ex = Entry(root, width =30)
    ex.pack()
    userlabel=Label(root,text="user")
    userlabel.pack()
    user=Entry(root,width=30)
    user.pack()
    loginlabel=Label(text="login")
    loginlabel.pack()
    login=Entry(root,width=30)
    login.pack()
    Label(root, text ="Destinataire : ").pack()
    des = Entry(root, width=30, background="white")
    des.pack()
     
    Label(root, text ="Titre : ").pack()
    ti = Entry(root, width=30, background="white")
    ti.pack()
     
     
    Label(root, text ="Message : ").pack()
    msg = Text(root, width=30, height=10, background="#EEE")
    msg.pack()
    smtp1=smtplib.SMTP()
    #Bouton + formule
    def envoie(*args):
     
        smtp1.connect(lab['text'],25)
        smtp1.login(user.get(),login.get())
        smtp1.sendmail(ex.get(),des.get(),msg.get('0.0',END))
        smtp1.quit()
    bouton=Button(root, command=envoie, text="Envoyer")
    bouton.pack()
     
    ##Insere le texte dans la fenetre
    root.mainloop()

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 16
    Points : 8
    Points
    8
    Par défaut
    j'ai une erreur kan je veut inserer le titre pour le mail.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    def envoie(*args):
     
        smtp1.connect(lab['text'],25)
        #smtp1.login(user.get(),login.get())
        smtp1.sendmail(ex.get(),des.get(),msg.get('0.0',END),ti.get())
        smtp1.quit()
    bouton=Button(root, command=envoie, text="Envoyer")
    bouton.pack()
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Exception in Tkinter callback
    Traceback (most recent call last):
      File "G:\Python-2.5\lib\lib-tk\Tkinter.py", line 1403, in __call__
        return self.func(*args)
      File "C:\Documents and Settings\Frelon_\Mes documents\python\tes.py", line 108, in envoie
        smtp1.sendmail(ex.get(),des.get(),msg.get('0.0',END),ti.get())
      File "G:\Python-2.5\lib\smtplib.py", line 684, in sendmail
        raise SMTPSenderRefused(code, resp, from_addr)
    SMTPSenderRefused: (555, 'Unsupported option: t', 'rom911@free.fr')

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut re: probleme envoie message
    la fonction sendmail prends trois parametre et non quatre
    il faut que tu ajoute ce code et que tu modifie senmail comme suit

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    from email.mime.base import MIMEBase
    from email.mime.multipart import MIMEMultipart
    msge=MIMEMultipart()
    msge['subject']=ti.get()
    msge['from']=ex.get()
    msge['to']=des.get()
    img=MIMEBase('text','plain')
    img.set_payload(msg.get('0.0',END))
    msge.attach(img)
    smtp1.sendmail(ex.get(),des.get(),msge.as_string())
    je crois que tu peu l inserer dans la fonction envoie a tester sauf les appel import que tu appelle en debut du programme

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut ton code avec ce qu il faut ajouter
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    import smtplib
     
    # -*- coding: cp1252 -*-
    from Tkinter import *
    import Tkinter as Tk
    import tkMessageBox as Msg
    from email.mime.base import MIMEBase
    from email.mime.multipart import MIMEMultipart
     
     
     
    ## Fenêtre principale
    root = Tk.Tk()   
    root.geometry("500x600")
    root.title("Envoie de mail")
    #root.iconbitmap("xp.ico")
     
    ##Fenetres du menu
    def About(): Msg.showinfo("A propos", "Version 1.0 \n Développer par Frelon")
     
     
    ## Barre de menu
    mainmenu = Tk.Menu(root)  
     
    ## Menu fils menuFichier
    menuFichier = Tk.Menu(mainmenu)
    ## Ajout d'une option au menu Fichier
    menuFichier.add_command(label="Quitter", command=root.destroy)
     
    ## Menu fils menuFichier
    menuHelp = Tk.Menu(mainmenu)
    ## Ajout d'une option au menu Help
    menuHelp.add_command(label="A propos", command=About)
     
    ##Option Menu Principale
    mainmenu.add_cascade(label = "Fichier", menu=menuFichier)
    mainmenu.add_cascade(label = "?", menu=menuHelp)
     
    ##Fin du Menu
    root.config(menu = mainmenu)
     
    ##Texte
    Label(root, text ="Envoyer des mails").pack()
     
     
     
    #Formule pour la liste
    def onSelect(e):
        select=listb.get(listb.curselection())
        lab.configure(text=select, fg="black")
        listb.configure()
        return select
     
     
    listb=Listbox(root)
    lab=Label(root,text="", fg="red")
    listb.pack()
    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.gawab.com","smtp.gmail.com","smtp.ifrance.com","smtp.laposte.net",
                       "mail.noos.fr","smtp.orange.fr","smtp.tele2.fr","smtp.tiscali.fr","smtp.wanadoo.fr",
                       "smtp.mail.yahoo.fr","smtp.wanadoo.fr"]:
            listb.insert(i,smtp)
            i+=1		
    # Un double click dans la liste appellera la fonction onSelect:		
    listb.bind('<Double-1>',onSelect)
     
     
     
     
    #Formulaire envoie mail
    Label(root, text ="Expéditeur : ").pack()
    ex = Entry(root, width =30)
    ex.pack()
    userlabel=Label(root,text="user")
    userlabel.pack()
    user=Entry(root,width=30)
    user.pack()
    loginlabel=Label(text="login")
    loginlabel.pack()
    login=Entry(root,width=30)
    login.pack()
    Label(root, text ="Destinataire : ").pack()
    des = Entry(root, width=30, background="white")
    des.pack()
     
    Label(root, text ="Titre : ").pack()
    ti = Entry(root, width=30, background="white")
    ti.pack()
     
     
    Label(root, text ="Message : ").pack()
    msg = Text(root, width=30, height=10, background="#EEE")
    msg.pack()
    smtp1=smtplib.SMTP()
    #Bouton + formule
    def envoie(*args):
        msge=MIMEMultipart()
        msge['subject']=ti.get()
        msge['from']=ex.get()
        msge['to']=des.get()
        img=MIMEBase('text','plain')
        img.set_payload(msg.get('0.0',END))
        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()
    bouton=Button(root, command=envoie, text="Envoyer")
    bouton.pack()
     
    ##Insere le texte dans la fenetre
    root.mainloop()

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 16
    Points : 8
    Points
    8
    Par défaut Grand merci
    Grand merci a toi je vait teste dsl de repondre aussi tard mais je bosse et jai pas le temp de regarder, mais merci encore!

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut pas de souci
    ca fait vraiment plaisir d aider les autres quand on le peu

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 16
    Points : 8
    Points
    8
    Par défaut probleme envoie piece jointe
    jai un prob pour envoyer des pieces jointe file le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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)
     
        fichiers=open(piece_jointe.get())
        msge.attach(fichiers)
     
        smtp1.connect(lab['text'],25)
        #smtp1.login(user.get(),login.get())
        smtp1.sendmail(ex.get(),des.get(),msge.as_string())
        smtp1.quit()
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    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')
    		coupfichier=nom_fichiers.split("/")
    		print "coupfichier :",nom_fichiers
    		nom_fichiers=coupfichier[-1]
    		print "Nom du fichier : ",nom_fichiers
    		piece_jointe.insert(0,nom_fichiers,)
    merci par avance

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut il me faudrai tout le code
    il faudrai que tu me presente tout le code et je pourrai essayer chez moi d envoyer des pieces jointes a++

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut pour ta fonction joindre
    il faudrait que tu recherche les extension pris en charge par les type mime

  11. #11
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 16
    Points : 8
    Points
    8
    Par défaut merci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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()
    voici mon code pour l'instant j'essaye d'envoyer un fichier texte comprenant quelle que info mais sa ne marche pas. j'envoie de Free --> Hotmail

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut non sa marche
    tu dois juste enlever changer le mode de enregistrer et envoyer ton mail

  13. #13
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 93
    Points : 81
    Points
    81
    Par défaut j oublie tu doit
    pas oublier de te logger dans ta fonction envoie ton identifiant smtp et ton mot de passe voili voilou voila a++

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Mail] envoi mail probleme avec from
    Par pascale86 dans le forum Langage
    Réponses: 1
    Dernier message: 06/06/2008, 15h48
  2. [Mail] probleme envoie mail
    Par phoeniix07 dans le forum Langage
    Réponses: 7
    Dernier message: 21/06/2006, 14h35
  3. [Mail] probleme d'envoi de mail
    Par Naruto_kun dans le forum Langage
    Réponses: 8
    Dernier message: 08/06/2006, 15h42
  4. [Mail] Probleme d'envoi d'e-mail
    Par pierrot10 dans le forum Langage
    Réponses: 1
    Dernier message: 24/04/2006, 15h33
  5. [Mail] Probleme pour l'envoi de mails avec mime
    Par tof91 dans le forum Langage
    Réponses: 1
    Dernier message: 09/03/2006, 16h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo