Gmail Mail Gui – Python Program

Hey guys i back after a long time with a new stuff.

I have created a simple Email Gui which can send an email but only for gmail users. Definately i will create and post a multipurpose email application but it then you guys try and create your own mailing window. It is all coded in simple python programming language, i have not used and structured programming or class and object method. I kept i simple and sorted.

The following modules and method i have covered up:

  • Tkinter module (for creating GUI)
  • SMTP module (for sending mail)
  • Functions (but obvious to call the logic written inside it)

*Note: Before using the application you have to Enable the Allow Less Secure Apps Option from setting > under Accounts and Import tab > Other Google Accounts Settings > Under Sign-In & Security tab > Connected apps and sites. Scroll a bit and there you will find the option to enable that.

Some Screenies down below and code (file is attached at the end of the article) :

gui_mail

 

Code:

from tkinter import *
import smtplib

f=Tk()
f.title(“Gmail Gui”)
send_email=StringVar()
send_pass=StringVar()
recv_email=StringVar()
msg_body=None
def layout():
menuBar=Menu(f)
menuBar.add_command(label=”Instructions”,command=instruct)
menuBar.add_command(label=”About”,command=about)
f.config(menu=menuBar)

sender_email=Label(f,text=”Sender’s Gmail ID: “)
sender_entry=Entry(f,textvariable=send_email,bd=3)
sender_pass=Label(f,text=”Sender’s Gmail Pass: “)
sender_passentry=Entry(f,show=’*’,textvariable=send_pass,bd=3)

receiver_email=Label(f,text=”Receiver’s Email: “)
receiver_entry=Entry(f,textvariable=recv_email,bd=3)

msg_label=Label(f,text=’Message’)
global msg_body
msg_body=Text(f,height=5,width=15,bd=3)

send=Button(f,text=’Send’,width=15,command=mail,bd=3)
cancel=Button(f,text=’Cancel’,width=15,command=destroy,bd=3)

sender_email.grid(row=0,column=0,padx=5,pady=3)
sender_entry.grid(row=0,column=1,padx=5,pady=3)
sender_pass.grid(row=1,column=0,padx=5,pady=3)
sender_passentry.grid(row=1,column=1,padx=5,pady=3)
receiver_email.grid(row=2,column=0,padx=5,pady=3)
receiver_entry.grid(row=2,column=1,padx=5,pady=3)
msg_label.grid(row=3,column=0,padx=5,pady=3)
msg_body.grid(row=3,column=1,padx=5,pady=3)
send.grid(row=4,column=0,padx=5,pady=3)
cancel.grid(row=4,column=1,padx=5,pady=3)
f.mainloop()

def destroy():
f.destroy()

def msg_box():
messagebox.showinfo(“Email Info”,”Mail Sent”)

def instruct():
messagebox.showinfo(“Instruction”,”switch ‘allow less secure apps’ to ON from\nhttps://myaccount.google.com/u/0/security?hl=en&pli=1#connectedapps\nbefore using the app!!”)

def about():
messagebox.showinfo(“About”,”This app is for only educational purpose\nCreated by Yagnesh Vakharia\nNon-Copywrite”)

def mail():
try:
if send_email.get()==”” or send_pass.get()==”” or recv_email.get()==””:
messagebox.showerror(“Error”,”Please enter the complete details.”)
else:
server=smtplib.SMTP(‘smtp.gmail.com’,587)
server.starttls()
a=send_email.get()
b=send_pass.get()
c=msg_body.get(‘1.0’,END)
d=recv_email.get()
server.login(a,b)
server.sendmail(a,d,c)
server.close()
msg_box()
except Exception as e:
print(e)
a=messagebox.askokcancel(“Error”,”Read instructions”)

layout()

 

So execute it and make sure you its for only educational purpose. Happy Programming. 

If you have any queries, more simplified programs or solutions then kindly comment below. Also you can Email me your doubts and queries related to program.

Thank You!

Attachment: Email_GUI.py

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s