Python Forum
Progress Bar While Sending an Email
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Progress Bar While Sending an Email
#1
Hello, I am trying to create a progress bar for my tkinter based gui that shows the user that an email is being sent. I've never successfully implemented threading or multi-processing before, simply because any application I thought I would need either of them, it was easier and faster without. My thought was that I would need to create a popup tkinter object with a progress bar that polls a separate function that sends the email. These two function would then be combined in a single caller function that uses concurrent.futures. I'm not really sure, however, how I can poll the send_mail function from the mail_waitbox function.

Here's the relevant code from my project:

class MainApplication(ttk.Frame):
    def __init__(self, parent, *args, **kwargs):
        ttk.Frame.__init__(self, parent, *args, **kwargs)

    #gui setup and variables.

        self.email_test_button = ttk.Button(self.email_tab, width=36, text="Test Email Settings", command=self.check_email)
        self.email_test_button.grid(row=11, column=1, padx=20, pady=5)

    def check_email_waitbox(self):
        popup = tk.Toplevel()
        popup_label = ttk.Label(popup, text="Message being sent").grid(row=0, column=0)
        progress = 0
        progress_var = tk.DoubleVar()
        progress_bar = ttk.Progressbar(popup, variable=progress_var, maximum=100)
        progress_bar.grid(row=1, column=0)

    def check_email_backend(self):
        t1=time.perf_counter()
        print(t1)
        sender_name = self.display_email_from.get()
        test = "testlog.txt"
        for x in self.display_email_recipient:
            recipients = [x]
        with open(test, "w+") as f:
            f.write(f"From: {sender_name}\n")
            f.write(f"To: {recipients}\n")
            f.write("Subject: Testing\n\n")
            f.write("This is a test mailer.")
        try:
            server = smtplib.SMTP_SSL(self.display_email_smtp.get(), self.display_email_port.get())
            server.ehlo()
            server.login(self.display_email_login.get(), self.display_email_passwd.get())
            with open(test) as fp:
                msg = EmailMessage()
                msg.set_content(fp.read())
            msg["Subject"] = "Test"
            msg["From"] = self.display_email_from.get()
            msg["To"] = recipients
            server.send_message(msg)
            server.close()
        except Exception as ex:
            if "getaddrinfo" in str(ex):
                messagebox.showerror("Something Went Wrong", "Check your settings or your internet connection before continuing.")
            if "A connection attempt failed" in str(ex):
                messagebox.showerror("something Went Wrong", f"Check your settings.\n\nError Returned: \n{ex}")
            print(ex)
        t2=time.perf_counter()
        print(t1 - t2)

    def check_email(self):
        self.check_email_backend()
        # with concurrent.futures.ThreadPoolExecutor() as executor:
        #     g1 = executor.submit(self.check_email_waitbox)
        #     g2 = executor.submit(self.check_email_backend)

if __name__ == "__main__":
    root = tk.Tk()
    MainApplication(root)
    root.mainloop()
Note: I know what I have won't work. I'm just not really sure how to proceed from here.
Reply


Messages In This Thread
Progress Bar While Sending an Email - by maxtimbo - Oct-08-2019, 02:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I measure progress and display it in the progress bar in the interface? Matgaret 2 5,879 Dec-11-2019, 03:30 PM
Last Post: Denni
  [Tkinter] Progress Bar While Sending an Email maxtimbo 3 3,999 Oct-09-2019, 09:13 PM
Last Post: woooee
  GUI Progress Bar Anysja 6 6,532 Aug-29-2018, 02:34 PM
Last Post: swetanjali
  [PyQt] cant import progress bar from another py file swipis 7 8,496 Dec-18-2016, 10:41 AM
Last Post: swipis

Forum Jump:

User Panel Messages

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