The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

GUI for Email Sender Script

Creating a GUI for an Email Sender script enhances usability, especially for non-technical users. Below is a full implementation of a Python-based GUI email sender using Tkinter, along with smtplib for sending emails.

python
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import tkinter as tk from tkinter import messagebox def send_email(): sender_email = sender_entry.get() password = password_entry.get() receiver_email = receiver_entry.get() subject = subject_entry.get() body = body_text.get("1.0", tk.END) if not (sender_email and password and receiver_email and subject and body.strip()): messagebox.showerror("Error", "All fields are required.") return try: msg = MIMEMultipart() msg['From'] = sender_email msg['To'] = receiver_email msg['Subject'] = subject msg.attach(MIMEText(body, 'plain')) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(sender_email, password) server.send_message(msg) server.quit() messagebox.showinfo("Success", "Email sent successfully!") except Exception as e: messagebox.showerror("Error", f"Failed to send email.n{e}") # GUI Setup root = tk.Tk() root.title("Email Sender GUI") root.geometry("500x500") root.resizable(False, False) # Sender Email tk.Label(root, text="Your Email:").pack(anchor='w', padx=10, pady=5) sender_entry = tk.Entry(root, width=60) sender_entry.pack(padx=10) # Password tk.Label(root, text="Password:").pack(anchor='w', padx=10, pady=5) password_entry = tk.Entry(root, show='*', width=60) password_entry.pack(padx=10) # Receiver Email tk.Label(root, text="Recipient Email:").pack(anchor='w', padx=10, pady=5) receiver_entry = tk.Entry(root, width=60) receiver_entry.pack(padx=10) # Subject tk.Label(root, text="Subject:").pack(anchor='w', padx=10, pady=5) subject_entry = tk.Entry(root, width=60) subject_entry.pack(padx=10) # Body tk.Label(root, text="Message:").pack(anchor='w', padx=10, pady=5) body_text = tk.Text(root, height=10, width=60) body_text.pack(padx=10) # Send Button send_button = tk.Button(root, text="Send Email", command=send_email, bg="green", fg="white") send_button.pack(pady=20) root.mainloop()

Features:

  • Input Fields: Sender email, password, receiver email, subject, and body.

  • Validation: Ensures no field is left empty.

  • Error Handling: Catches and displays exceptions (e.g., login failure, network errors).

  • Security Note: Use App Passwords for Gmail instead of the main password.

Optional Enhancements:

  • Attachments support with filedialog and MIMEApplication

  • Dropdowns for predefined email templates

  • Logging system for sent emails

  • Styling improvements with ttk or third-party GUI frameworks like PyQt or Kivy

This GUI script provides a user-friendly way to send emails programmatically, bridging the gap between code and usability.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About