Python Forum
How can a user send a message via Contact Form in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can a user send a message via Contact Form in tkinter
#1
I am trying to create a GUI app in Tkinter that allows user to send an email to me with a query. This will be done via the contact form. All my code to date (for the actual app) is done using Tkinter. I am NOT asking for explaining me how to put a window and widgets in Tkinter. I am asking how to incorporate smptlib module in my case. I would like user to send a query without authorisation like passwords etc.
In my code below the sender and receiver will be the same email address (my email) which is not ideal. I can request the user to input his contact details in the message format but would prefer that the email I receive is linked to the user email address so I can simple reply to his query.

Hope somebody can advise?

import smtplib
import tkinter as tk
from tkinter import ttk
 
class Contact():

    def __init__(self, the_window):

        self.the_window = the_window
        self.the_window.title("Contact Form")
        self.the_window.geometry("500x400")
        self.the_window.attributes('-topmost',True)

        self.sender_box = tk.StringVar()
        self.name_sender = tk.StringVar()

        self.create_widgets()

    def btn_clicked(self):

        sender = self.sender_box_entry.get()
        message = self.mess_box_entry.get('1.0', 'end')
        receiver = "ssss@hotmail.com"
        login = "ssss@hotmail.com"
        password = "xxxxxx"


        try:
            server = smtplib.SMTP("smtp.live.com", 25)
            server.ehlo()
            server.starttls()
            server.login(login, password)
            server.sendmail(sender, receiver, message)
            server.quit()
            statement_1 = "MAIL HAS BEEN SENT"
            return statement_1

        except:

            statement_2 = "SOMETHING WENT WRONG"
            return statement_2


    def display_mess(self, btn_clicked):
        self.display['text'] = btn_clicked()


    def create_widgets(self):

        self.sender_label = tk.Label(self.the_window, text="Sender Email")
        self.name_sender_label = tk.Label(self.the_window, text="Name")
        self.message = tk.Label(self.the_window, text="Write your query below")
        self.display = tk.Label(self.the_window)
        self.sender_box_entry = ttk.Entry(self.the_window, textvariable=self.sender_box)
        self.name_box_entry = ttk.Entry(self.the_window, textvariable=self.name_sender)
        self.mess_box_entry = tk.Text(self.the_window, width=55, height=10, wrap=tk.WORD)
        self.button_send = ttk.Button(self.the_window, text="Send", command= lambda:self.display_mess(self.btn_clicked))

        self.sender_label.grid(row=0, column=0, pady=(20,0))
        self.sender_box_entry.grid(row=0, column=1, pady=(20,0))
        self.name_sender_label.grid(row=1, column=0)
        self.name_box_entry.grid(row=1, column=1)
        self.message.grid(row=3,column=0, columnspan=2, pady=(20,0))
        self.mess_box_entry.grid(row=4,column=0, columnspan=2, padx=30)
        self.button_send.grid(row=5,column=1, pady=(10,0))
        self.display.grid(row=5, column=0, padx=(20,0))

new_window = tk.Tk()
application = Contact(new_window)
new_window.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Python - Tkinter : How can I send path Excel from GUI to scripte johnjh 2 647 Aug-28-2020, 05:38 PM
Last Post: maaad
  Convert combobox user input in to date with tkinter Ame 8 1,404 Jul-01-2020, 09:40 PM
Last Post: Yoriz
  [Tkinter] Help me,send message via tkinter chano 2 804 May-15-2019, 08:59 AM
Last Post: chano
  set time & date by user in tkinter gray 3 12,568 Mar-20-2017, 04:00 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020