I'm kinda new to python and tried to write a little email client. The goal is to select your favorite email service and login into your email. I'm using if statements to select the respective smtp server / email service. But it seems not to work, my program is always selecting the last statement and i dont have a clue to fix it. ( the ability to send emails is not finished yet) I would also be thankfull for some ideas about a new method to select the specific smtp server :)
from tkinter import *
from tkinter import ttk
import smtplib
import tkinter as tk
import ssl
fenster = Tk()
fenster.title('ITA-Projekt')
fenster.geometry('330x280')
tabControl = ttk.Notebook(fenster)
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
tabControl.add(tab1, text ='Login')
tabControl.add(tab2, text ='Email verfassen')
#Auswahl Liste
Liste = [
"Gmail",
"Yahoo mail",
"GMX",
"Web.de",
]
auswahl_var = tk.StringVar(tab1)
auswahl_var.set(Liste[0])
opt = tk.OptionMenu(tab1, auswahl_var, *Liste)
opt.config(width=8,height=0)
opt.place(x=215, y=10)
#Tab1
LoginEntry = ttk.Entry(tab1, show="*")
EmailEntry = ttk.Entry(tab1)
LoginLabel = ttk.Label(tab1,text='Passwort:')
LoginLabel.grid(row=1, column=0)
EmailLabel = ttk.Label(tab1,text='Email:')
EmailLabel.grid(row=0, column=0)
LoginEntry.grid(row=1, column=2, padx=15, pady=15)
EmailEntry.grid(row=0, column=2, padx=15, pady=15)
#buttonLogin = ttk.Button(tab1, text="Login", command=Einloggen)
#buttonLogin.place(x=90, y=140)
buttonAusloggen = ttk.Button(tab1, text="Ausloggen")
buttonAusloggen.place(x=90, y=170)
tabControl.pack(expand = 1, fill ="both")
def Einloggen():
Email = EmailEntry.get()
Passwort = LoginEntry.get()
if (auswahl_var == "Gmail"):
smtp_objekt = smtplib.SMTP('smtp.gmail.com', 587)
smtp_objekt.ehlo()
smtp_objekt.starttls()
smtp_objekt.ehlo()
smtp_objekt.login(Email, Passwort)
else:
if (auswahl_var == "Yahoo mail"):
server = smtplib.SMTP('smtp.mail.yahoo.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(Email, Passwort)
else:
if (auswahl_var == "GMX"):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(Email, Passwort)
else:
server = smtplib.SMTP('smtp.web.de', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(Email, Passwort)
buttonLogin = ttk.Button(tab1, text="Login", command=Einloggen)
buttonLogin.place(x=90, y=140)
#Tab2
EmpfEntry = ttk.Entry(tab2)
BetreffEntry = ttk.Entry(tab2)
BodyEntry = ttk.Entry(tab2)
EmpfLabel = ttk.Label(tab2,text='Empfänger:')
EmpfLabel.grid(row=0, column=0)
BetreffLabel = ttk.Label(tab2,text='Betreff:')
BetreffLabel.grid(row=1, column=0)
EmpfEntry.grid(row=1, column=2, padx=15, pady=15)
BetreffEntry.grid(row=0, column=2, padx=15, pady=15)
BodyEntry.grid(row=2, column=2, padx=15, pady=15)
buttonSenden= ttk.Button(tab2, text="Senden")
buttonSenden.place(x=90, y=140)
fenster.mainloop()
Aucun commentaire:
Enregistrer un commentaire