How do I use Python Tkinter with sending mail?

I am trying to use Tkinter to make a program to send mail but I can't get the window to pop up before it try to send the mail. How would i do this?


import smtplib
from Tkinter import *


entry=Entry(root, textvariable=v)

sender = ""
receiver = [v]
message = """From: <>
Subject: I made a code to send this!
Hello i made a code to send this!"""

    session = smtplib.SMTP('',25)

except smtplib.SMTPException as e:

Programs that use a windowing system operate using events of some sort. On Windows the system generates windows messages for things like window creation, user input and so on. A program has to continually process events and respond to appropriate messages in a timely manner.

In tkinter this is done by calling the tkinter mainloop function as the final action in your code. This starts the program processing events. In such a program, sending a mail messages is then done in response to an event. That could be the user clicking a button or menu item or in response to a timer or window creation event.

The reason you see no graphical UI is that as your program executes it queues a number of events for itself but it exits before it ever processes any of them. So the window creation event, map event, paint event and all the others are never processed and one the process exits the system will discard them all.

Python Tkinter GUI Script to Send Email Using , Welcome folks today in this blog post i will be discussing about how to send mails using smtplib library in Tkinter GUI. A step by step instruction� The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon. SMTP stands for Simple Mail Transfer Protocol. The smtplib modules is useful for communicating with mail servers to send mail. Sending mail is done with Python’s smtplib using an SMTP server.

import smtplib

from smtplib import SMTPException

#this app sends email  via gmail
def gmail( ):
    usermail = user_email.get()
    #This allow you to include a subject by adding from, to and subject 
    main_message=body.get('1.0', 'end-1c')
    Body="""From: Name here <usermail>
    To: <receivermail>

    """ %(subject,main_message )

            server.login(usermail, pass_word  )
            server.sendmail(usermail,receivermail, Body )

            text.insert(1.0, 'message sent')
         #error handling
         except  (smtplib.SMTPException,ConnectionRefusedError,OSError):
            text.insert(1.0, 'message not sent')

#Gui interface
from tkinter import*

root= Tk(className=" Gmail app " )
root.config(bg="brown", )

#user mail
user_email = Label(root, text="Enter your Gmail address:  ")
user_email.config(bg="black", fg="white")

user_email = Entry(root, bd =8)

#receiver email
receiver_email = Label(root, text="Enter the recipient's email address:
receiver_email.pack( )
receiver_email.config(bg="black", fg="white")

receiver_email = Entry(root, bd =8)

#subject line
subj= Label(root, text="Enter your subject here: ")
subj.pack( )
subj.config(bg="black", fg="white")

subj = Entry(root, bd =8)

#Body of the message
body = Text(root, font="Tahoma",  relief=SUNKEN , bd=8)
body.config(bg="pink", height=15)
body.pack(fill=BOTH, expand=True)

#password widget
password = Label(root, text="Enter your Gmail password:  ")
password.config(bg="black", fg="white")

password= Entry(root, show='*', bd =8)

#submit button
submit_mail = Button(root, bd =8, text="Click here to submit the mail",  

#feed back
text = Text(root, font="Tahoma",  relief=SUNKEN , bd=8)
text.config(bg="pink",  height=2)
text.pack(fill=BOTH, expand=True)


the problem with my code above is that it can not send subject , only body can be sent. I am also amateur with two months self learning. i will recommend that you learn tkinter from this forum, yputube and a book called 'an introduction to tkinter by David Beazely'. hope this helps

Python Tkinter GUI Script to Send Email Using Smtplib , Python Tkinter GUI Script to Send Email Using Smtplib Library Full Project For Beginners Duration: 13:51 Posted: Jun 28, 2020 Set up a secure connection using SMTP_SSL () and .starttls () Use Python’s built-in smtplib library to send basic emails. Send emails with HTML content and attachments using the email package. Send multiple personalized emails using a CSV file with contact data.

You can shorten the lines for sending an email by replacing

session = smtplib.SMTP('',25)


session = SMTP_SSL('',465) ## Makes a connection with SSL, no starttls() required
session.login(sender, 'passwrd')
session.sendmail(sender, receiver ,message)

Port 465 is used for authenticated SMTP over TLS/SSL.

You don't have to write the function ehlo() and starttls(), because they are called automatically. starttls() is only called when you use SMTP_SLL().

You actually can even ignore the function quit(), because it's called after a while.

Login panel to send emails and create database, In this video you will see how to log in , Sign up , send mail for of the application that you Duration: 5:45 Posted: Jan 2, 2018 Python Sending Email using SMTP. Simple Mail Transfer Protocol (SMTP) is used as a protocol to handle the email transfer using Python. It is used to route emails between email servers. It is an application layer protocol which allows to users to send mail to another. The receiver retrieves email using the protocols POP (Post Office Protocol) and IMAP (Internet Message Access Protocol).

Create An Awesome email program in Python tkinter gui app , Create an incredible email program in python tkinter with your gmail or Yahoo account. My Duration: 13:34 Posted: Feb 5, 2017 The smtplibis a Python library for sending emails using the Simple Mail Transfer Protocol (SMTP). The smtplibis a built-in module; we It abstracts away all the complexities of SMTP.

arka-nitd/send-email-gui: A GUI based program made , Application to send email to any gmail account. A GUI based program made using tkinter to send email using SMTP module of python. For installation of tkinter� For example, on my laptop the command is. cd c:\users\donovan\downloads. Hit enter, then type in. py And hit enter again. The command line app will now load, and it will prompt you for the your login details, your message, and who you want to send the message to! Ask Question.

Is it possible to send emails with Tkinter? : learnpython, I wrote a small program that I plan to use on school computers that gives me information about elements and common polyatomic ions using python 3.8.5. I� To add several more recipients, you can just type their addresses in separated by a comma, add CC and BCC. But if you work with a bulk email sending, Python will save you with loops. One of the options is to create a database in a.csv format (we assume it is saved to the same folder as your Python script).

  • Thank you. So I need to put a main loop in the code and to add the send mail code to a button or object right?