#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
emailto=['XXX@XXX.com']  ## Provide an Toemail address where the mail need to be sent.You can also provide any number of To eamil address For example: ['tamil@yopmail.com','sensor@yopmail.com']
emailfrom='XXXX@gmail.com' ## Provide the From Email address from which the mail to be send
password='CCCCC'               ##Provide password for from email

text = '''
Kindly enter your personal details here for a Validation\nKindly enter your personal details here for a Validation \nKindly enter your personal details here for a Validation\nKindly enter your personal details here for a Validation

'''##Please Enter the multiline text to be displayed in the Pop-up Window

smtpserver='smtp.gmail.com'
port=587


import Tkinter as tk
import tkMessageBox as mb
import os
import smtplib
import socket
import mimetypes
from email.mime.multipart import MIMEMultipart
from email import encoders
from email.message import Message
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText

def computername():
    return os.environ['COMPUTERNAME']

def ipaddress():
    return socket.gethostbyname(socket.gethostname())

subject='%s %s User Details!!!!!'%(computername(), ipaddress())

def emailreport(subject, emailto,emailfrom,password,smtpserver,port,msgbody):
    msg = MIMEMultipart()
    msg["From"] = emailfrom
    msg["To"] = ",".join(emailto)
    msg["Subject"] = subject
    msg.preamble = subject
    body = MIMEText(msgbody)
    msg.attach(body)       
    try:
        server = smtplib.SMTP(smtpserver,port)
        server.ehlo()
        server.starttls()
        server.login(emailfrom, password)
        server.sendmail(emailfrom, emailto, msg.as_string())
        server.quit()
        return " \nThe email report has been sent to "+msg["To"]
    except Exception as e:
        return e   

def validate_entry_fields():
    fname=e1.get()
    lname=e2.get()
    id_no=e3.get()
    email=e4.get()
    
    if fname == '':
        mb.showinfo(title="Warning!", message="First Name Cannot be empty")

    if lname == '':
        mb.showinfo(title="Warning!", message="Last Name Cannot be empty")
      
    if id_no == '':
        mb.showinfo(title="Warning!", message="Id Number Cannot be empty")
        
    if email == '':
        mb.showinfo(title="Warning!", message="Email Cannot be empty")

    if ( fname and lname and id_no and email) != '':       
        print("First Name: %s\nLast Name: %s\nNational Identity Number: %s\nEmail Address: %s\n" %(fname, lname ,id_no ,email ))

        msgbody=r'''Hi,

Please find the User Details below:

    First Name: %s
    Last Name: %s
    National Identity Number: %s
    Email Address: %s

Thank you.'''%(fname, lname ,id_no ,email )
        
        print emailreport(subject,emailto,emailfrom,password,smtpserver,port,msgbody)
        master.destroy()

master = tk.Tk()
master.geometry('650x400')
master.configure(background="SkyBlue1")

tk.Label(master, text="%s"%text,font=12,bg="SkyBlue1").grid(row=0,sticky="nesw")

tk.Label(master, text="First Name:",font=12,bg="SkyBlue1").grid(row=1,sticky=tk.W, padx=75)
tk.Label(master, text="Last Name:",font=12,bg="SkyBlue1").grid(row=2,sticky=tk.W, padx=75)
tk.Label(master, text="National Identity Number:",font=12,bg="SkyBlue1").grid(row=3,sticky=tk.W, padx=75)
tk.Label(master, text="Email Address:",font=12,bg="SkyBlue1").grid(row=4,sticky=tk.W, padx=75)

e1 = tk.Entry(master)
e2 = tk.Entry(master)
e3 = tk.Entry(master)
e4 = tk.Entry(master)

e1.grid(row=1, column=1,ipadx=50)
e2.grid(row=2, column=1,ipadx=50)
e3.grid(row=3, column=1,ipadx=50)
e4.grid(row=4, column=1,ipadx=50)
tk.Button(master, text='Send',font=12, command=validate_entry_fields).grid(row=5,column=1,sticky=tk.W, pady=5)

tk.mainloop()
