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
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.sender_box = tk.StringVar()
        self.name_sender = tk.StringVar()


    def btn_clicked(self):

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

            server = smtplib.SMTP("", 25)
            server.login(login, password)
            server.sendmail(sender, receiver, message)
            statement_1 = "MAIL HAS BEEN SENT"
            return statement_1


            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)

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

Forum Jump:

User Panel Messages

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